Created
November 11, 2016 14:42
-
-
Save juanmaguitar/acbb4d6cbd518853523286a7de52cb1e to your computer and use it in GitHub Desktop.
bind
This file contains hidden or 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
function saySomething( message, name ) { | |
console.log (message + " " + name + "!") | |
} | |
saySomething("Hi", "juanma") // "Hi juanma!" | |
saySomething("Bye", "juanma") // "Bye juanma!" | |
var sayHi = saySomething.bind(null, "Hi"); | |
typeof sayHi === 'function' // true | |
sayHi("juanma") // "Hi juanma!" | |
var sayBye = saySomething.bind(null, "Bye"); | |
typeof sayBye === 'function' // true | |
sayBye("juanma") // "Bye juanma!" | |
var sayHiToJuanma = saySomething.bind(null, "Hi", "juanma"); | |
sayHiToJuanma() // "Hi juanma!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment