Last active
March 31, 2019 10:46
-
-
Save shahnawaz/170f87286126ca2cdc3e2c8a75caa140 to your computer and use it in GitHub Desktop.
This file contains 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
/* Our greeting function */ | |
function greeting(message) { | |
return `${this.name}! ${message}`; | |
} | |
/* Person we will be greeting */ | |
const Person = { | |
name: 'Don Joe' | |
}; | |
/* .bind() */ | |
// creating a bounded (with Person context) greeting function; to call later | |
const greetingForDonJoe = greeting.bind(Person, 'Welcome to the world of Tech Craft'); | |
// Lets call our new bounded function | |
greetingForDonJoe(); | |
// Returns: "Don Joe! Welcome" | |
/* .apply() */ | |
greeting.apply(Person, ['Welcome to the world of Tech Craft']); | |
// Returns: "Don Joe! Welcome to the world of TechCrafts" | |
/* .call() */ | |
greeting.call(Person, 'Welcome to the world of Tech Craft'); | |
// Returns: "Don Joe! Welcome to the world of TechCrafts" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment