Created
April 10, 2018 18:23
-
-
Save dvlden/c7b5684e1d64b084d65f95c492a16285 to your computer and use it in GitHub Desktop.
Just testing the "call, apply and bind"...
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
// 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