Created
June 19, 2013 18:40
-
-
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/
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
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