Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Simplest bind function
* bind
* Takes a function and returns a new one that will always have a particular context.
* If arguments are given, curry will happen:
* @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 = [], 2);
return function () {
return fn.apply(ctx || this, args.concat([], 0)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment