Skip to content

Instantly share code, notes, and snippets.

@ibolmo
Created August 3, 2011 14:02
Show Gist options
  • Save ibolmo/1122709 to your computer and use it in GitHub Desktop.
Save ibolmo/1122709 to your computer and use it in GitHub Desktop.
Function.prototype.bind = function(bind){
var self = this, args = Array.slice(arguments), args = (args.length > 1) ? args.slice(1) : null;
return function bound(){
if (this instanceof bound){
var F = function(){};
F.prototype = new self;
bind = new F;
}
args = args.concat(Array.slice(arguments));
var result = !args ? self.call(bind) : self.apply(bind, args);
return F ? bind : result;
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment