Skip to content

Instantly share code, notes, and snippets.

@ashishpaul99
Last active January 23, 2025 09:20
Show Gist options
  • Save ashishpaul99/3b293e8f17ef806f4942fd95e88b6abe to your computer and use it in GitHub Desktop.
Save ashishpaul99/3b293e8f17ef806f4942fd95e88b6abe to your computer and use it in GitHub Desktop.
call, apply, bind method
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"]);
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();
// 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