Created
August 18, 2023 16:26
-
-
Save suhailgupta03/1155e7f47a75b596243d7cc4991fe6e5 to your computer and use it in GitHub Desktop.
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 person = { | |
firstName: "Vikash", | |
lastName: "Sagar", | |
fullName: function() { | |
return this.firstName + " " + this.lastName; | |
} | |
} | |
console.log(person.fullName()); // Output: Vikash Sagar | |
let person1 = { | |
firstName: "John", | |
lastName: "Doe" | |
} | |
console.log(person.fullName.call(person1)); // Output: John Doe | |
// call function changes the context of this keyword to the person1 object. | |
let person2 = { | |
firstName: "Kapil", | |
lastName: "Jatav" | |
} | |
console.log(person.fullName.call(person2)); // Output: John Doe |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bind function