Create a gist now

Instantly share code, notes, and snippets.

@nutbread /bind.js Secret
Created Jan 15, 2015

What would you like to do?
Faster function binding than function.bind(...)
var bind = function (callback, self) {
if (arguments.length > 2) {
var slice = Array.prototype.slice,
push = Array.prototype.push,
args = slice.call(arguments, 2);
return function () {
var full_args = slice.call(args);
push.apply(full_args, arguments);
return callback.apply(self, full_args);
};
}
else {
return function () {
return callback.apply(self, arguments);
};
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment