Skip to content

Instantly share code, notes, and snippets.

@mateuszkocz
Created June 19, 2013 18:40
Show Gist options
  • Save mateuszkocz/5816770 to your computer and use it in GitHub Desktop.
Save mateuszkocz/5816770 to your computer and use it in GitHub Desktop.
Function returning function for convenience. Also Function.prototype.apply(). Source: http://yehudakatz.com/2011/08/11/understanding-javascript-function-invocation-and-this/
var bind = function(func, thisValue) {
return function() {
return func.apply(thisValue, arguments);
}
}
var boundHello = bind(person.hello, person);
boundHello("world") // "Brendan Eich says hello world"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment