// .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
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter