Skip to content

Instantly share code, notes, and snippets.

@shahnawaz
Last active March 31, 2019 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shahnawaz/170f87286126ca2cdc3e2c8a75caa140 to your computer and use it in GitHub Desktop.
Save shahnawaz/170f87286126ca2cdc3e2c8a75caa140 to your computer and use it in GitHub Desktop.
/* 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