Skip to content

Instantly share code, notes, and snippets.

@r3wt
Last active December 5, 2019 18:24
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 r3wt/67f9fbe900d616cd479c65763dd0f7cb to your computer and use it in GitHub Desktop.
Save r3wt/67f9fbe900d616cd479c65763dd0f7cb to your computer and use it in GitHub Desktop.
function bind()
/* partial implementation of Function.prototype.bind */
Function.prototype.bind || (Function.prototype.bind = function(/* context[,arg1,arg2...] */) {
var fn = this;
var args = Array.prototype.slice.call(this,arguments);//preset args
var context = args.shift() || undefined;
return function(){
var args2 = args.concat( Array.prototype.slice.call(arguments) );//spec states any passed args should be appended to preset arguments.
return fn.apply(context,args2);
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment