-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
afbd313
commit 29a1056
Showing
1 changed file
with
13 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,16 @@ | ||
//Revice new key word | ||
/***** | ||
so new does 3 things. | ||
1. creates object of fucntion name | ||
2. this of that aobject will be the values of object and | ||
new will return this | ||
3. and new will create link between the function's | ||
object and prototype of it directel;y for that we do not have | ||
to do that way | ||
const Object1 = Object.create(functionName.prototype) | ||
this thing will be handled by new keyword below is example | ||
*/ | ||
|
||
function exampleFunction(firstname, contact){ | ||
this.firstname=firstname; | ||
this.Mob= contact | ||
function createUser(firstName, Lastname, age,email){ | ||
this.firstName = firstName | ||
this.Lastname= Lastname; | ||
this.age = age | ||
this.email = email | ||
} | ||
exampleFunction.prototype.exampleInfo=function(){ | ||
console.log(this.Mob, this.firstname) | ||
|
||
createUser.prototype.userInfo = function(){ | ||
return `${this.firstName} ${this.Lastname} ${this.age} ${this.email}` | ||
} | ||
const example1 = new exampleFunction('vaibhav', 91584023023) | ||
/*** | ||
now new will create object of the function and return's this fot it | ||
now if we create prototype of exampleFunction and we create new instance | ||
of exampleFunciton new key word create direct link between the prototype | ||
and function this value e.g., as can be seen | ||
*/ | ||
|
||
example1.exampleInfo() | ||
createUser.prototype.sing= function(){ | ||
return `lalal alala la ala `; | ||
} | ||
const User1= new createUser("Vaibhav", "singh", 234, 'vai1641996@gmail.com') | ||
console.log(User1.userInfo()) |