Last active
December 5, 2019 18:24
-
-
Save r3wt/67f9fbe900d616cd479c65763dd0f7cb to your computer and use it in GitHub Desktop.
function bind()
This file contains hidden or 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
/* 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