this deep concept | javascript

PHOTO EMBED

Fri Apr 19 2024 07:49:16 GMT+0000 (Coordinated Universal Time)

Saved by @gitjck #javascript

// .call(), in call() method first argument must be a object. and function didnot need a parameter for recieve it, it can be accsses by this 
const person = {
	firstName: 'jigar1',
  fullName: function(abc) {
    console.log('--->',this.firstName  + " " +  abc);
    // return abc.firstName + " " + this.lastName;
  }
}
const person1 = {
  firstName:"John",
  lastName: "Doe"
}
const person2 = {
  firstName:"Mary",
  lastName: "Doe"
}
const person3 = {
    firstName: 'krishiv',
    myfun: function () {
        person.fullName.call(this,'jck');
    },
    funn3: function () {
        funn.call(this);
    }
}
 
function funn (hi) {
    console.log('*****',hi, this.firstName);
    person.fullName.call(this,'jck');	// --- krishiv jck
    person.fullName('jck');	        //  --- jigar1 jck
}
person3.myfun();					//--- krishiv jck
person3.funn3();					//***** undefined krishiv
person.fullName.call(this,'jck');	// --- undefined jck
person.fullName('jck');				//--- jigar1 jck
content_copyCOPY

// .call(), in call() method first argument must be a object. and function did not need a parameter to receive it, it can be accessible by this