Created
August 15, 2011 17:08
-
-
Save cms/1147214 to your computer and use it in GitHub Desktop.
Function.prototype.bind shim
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
if (typeof Function.prototype.bind != 'function') { | |
Function.prototype.bind = (function () { | |
var slice = Array.prototype.slice; | |
return function (thisArg) { | |
var target = this, boundArgs = slice.call(arguments, 1); | |
if (typeof target != 'function') throw new TypeError(); | |
function bound() { | |
var args = boundArgs.concat(slice.call(arguments)); | |
target.apply(this instanceof bound ? this : thisArg, args); | |
} | |
bound.prototype = (function F(proto) { | |
proto && (F.prototype = proto); | |
if (!(this instanceof F)) return new F; | |
})(target.prototype); | |
return bound; | |
}; | |
})(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment