Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@xulapp
Created July 31, 2011 17:33
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 xulapp/1116996 to your computer and use it in GitHub Desktop.
Save xulapp/1116996 to your computer and use it in GitHub Desktop.
bind ES3
Function.prototype.bind = Function.prototype.bind || function bind(thisArg) {
var method = this;
var args = Array.prototype.slice.call(arguments, 1);
return function bound() {
var _args = args.concat(Array.prototype.slice.call(arguments));
if (!(this instanceof bound))
return method.apply(thisArg, _args);
var __args = [];
for (var i = 0, len = _args.length; i < len; i++)
__args.push('_args[' + i + ']');
return eval('new method(' + __args.join(',') + ')');
};
}
@yahiaboudah
Copy link

nice one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment