Skip to content

Commit

Permalink
Revised about new keyword in JS
Browse files Browse the repository at this point in the history
  • Loading branch information
vaibhav164 committed Jul 25, 2024
1 parent afbd313 commit 29a1056
Showing 1 changed file with 13 additions and 27 deletions.
40 changes: 13 additions & 27 deletions demo/52_Object.js
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())

0 comments on commit 29a1056

Please sign in to comment.