Skip to content

Instantly share code, notes, and snippets.

@juanmaguitar
Created November 11, 2016 14:42
Show Gist options
  • Save juanmaguitar/acbb4d6cbd518853523286a7de52cb1e to your computer and use it in GitHub Desktop.
Save juanmaguitar/acbb4d6cbd518853523286a7de52cb1e to your computer and use it in GitHub Desktop.
bind
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