Skip to content

Instantly share code, notes, and snippets.

@pangers
Created January 23, 2016 09:58
Show Gist options
  • Save pangers/208be119f0797a4ac5d9 to your computer and use it in GitHub Desktop.
Save pangers/208be119f0797a4ac5d9 to your computer and use it in GitHub Desktop.
var footballer = {
name: "Leo Messi"
};
var basketballer = {
name: "Steph Curry"
};
var fighter = {
name: "Conor McGregor"
};
function giveMeTheName(occupation) {
return this.name + ", " + occupation;
}
giveMeTheName.apply(footballer, ["the footballer"]); //returns Leo Messi, the footballer
giveMeTheName.call(basketballer, "the basketballer"); //returns Steph Curry, the basketballer
giveMeTheName.bind(fighter)("the fighter"); // returns Conor McGregor, the fighter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment