-
-
Save nutbread/fbdb8970e0a8c8124742 to your computer and use it in GitHub Desktop.
Faster function binding than function.bind(...)
This file contains 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
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