Skip to content

Instantly share code, notes, and snippets.

@dvlden
Created April 10, 2018 18:23
Show Gist options
  • Save dvlden/c7b5684e1d64b084d65f95c492a16285 to your computer and use it in GitHub Desktop.
Save dvlden/c7b5684e1d64b084d65f95c492a16285 to your computer and use it in GitHub Desktop.
Just testing the "call, apply and bind"...
// I never really understood them, but now I think I got it...
let anObject = {
name: 'Nenad',
age: 25
};
let myArguments = ['Serbia', 'Valjevo', 'in a relationship'];
let anFunction = function (country, city, relationshipStatus) {
return `Hello, my name is ${this.name} and I'm ${this.age} y/o. I was born in ${country}, small city ${city} and I'm currently ${relationshipStatus}.`;
};
// anFunction.call(anObject, 'Serbia', 'Valjevo', 'in a relationship');
// anFunction.apply(anObject, myArguments);
// let bound = anFunction.bind(anObject);
// bound('Serbia', 'Valjevo', 'in a relationship');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment