Created
November 6, 2013 22:42
-
-
Save maruf89/7345543 to your computer and use it in GitHub Desktop.
Experimenting with a polyfill for 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
Function.prototype.bind = function(obj) { | |
if (Function.prototype.bind) { return Function.prototype.bind.apply(this, arguments) } | |
var that = this, | |
slice = function(a, b) { return a.length - (b || 0) ? Array.prototype.slice.call(a, b || 0) : [] }, | |
concat = function(a, b) { return a.length ? b.length ? a.concat(b) : a : b; }, | |
args = slice(arguments, 1); | |
return function() { | |
that.apply(obj, concat(args, slice(arguments))); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment