Skip to content

Instantly share code, notes, and snippets.

@cms
Created August 15, 2011 17:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cms/1147214 to your computer and use it in GitHub Desktop.
Save cms/1147214 to your computer and use it in GitHub Desktop.
Function.prototype.bind shim
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