-
-
Save gnclmorais/bd3ec4328240f724bd32 to your computer and use it in GitHub Desktop.
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
/** | |
* bind | |
* Takes a function and returns a new one that will always have a particular context. | |
* If arguments are given, curry will happen: http://ejohn.org/blog/partial-functions-in-javascript/ | |
* | |
* @param {Function} fn Function whose context will be changed | |
* @param {Object} [ctx=this] the obejct to which the context will be set | |
* @param {Mixed} [args...] Arguments to be passed to the resulting function | |
* @returns {Function} | |
*/ | |
var bind = function (fn, ctx /*,args*/) { | |
var args = [].slice.call(arguments, 2); | |
return function () { | |
return fn.apply(ctx || this, args.concat([].slice.call(arguments, 0))); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment