Skip to content

Instantly share code, notes, and snippets.

@nutbread

nutbread/bind.js Secret

Created January 15, 2015 00:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nutbread/fbdb8970e0a8c8124742 to your computer and use it in GitHub Desktop.
Save nutbread/fbdb8970e0a8c8124742 to your computer and use it in GitHub Desktop.
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