Skip to content

Instantly share code, notes, and snippets.

@gnclmorais gnclmorais/bind.js forked from Couto/bind.js
Last active Aug 29, 2015

Embed
What would you like to do?
/**
* 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
You can’t perform that action at this time.