Last active
January 23, 2025 09:20
-
-
Save ashishpaul99/3b293e8f17ef806f4942fd95e88b6abe to your computer and use it in GitHub Desktop.
call, apply, bind method
This file contains hidden or 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
let printFullName=function([hometown,state]){ | |
console.log(this.firstname+" "+this.lastname+" from "+hometown+" "+state); | |
} | |
let name1={ | |
firstname:"Ashish", | |
lastname:"Paul", | |
} | |
let name2={ | |
firstname:"sachin", | |
lastname:"Tendulkar" | |
} | |
printFullName.call(name1,["hyderabad","telangana"]); | |
printFullName.call(name2,["Mumbai","Maharashtra"]); |
This file contains hidden or 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
let printFullName=function(hometown,state){ | |
console.log(this.firstname+" "+this.lastname+" from "+hometown+" "+state); | |
} | |
let name1={ | |
firstname:"Ashish", | |
lastname:"Paul", | |
} | |
let name2={ | |
firstname:"sachin", | |
lastname:"Tendulkar" | |
} | |
const printName=printFullName.bind(name1,"Hyderabad","telangana"); | |
printName(); |
This file contains hidden or 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
// 1. Call( ) Method | |
// eg-1: | |
const student1={ | |
name:"Ashish", | |
printName:function(){ | |
console.log(this.name); | |
} | |
} | |
student1.printName() | |
const student2={ | |
name :"Paul" | |
} | |
student1.printName.call(student2); | |
// eg-2: | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment