Skip to content

Instantly share code, notes, and snippets.

@manar007
Last active July 19, 2018 23:12
Show Gist options
  • Save manar007/299fb93a69b5d7703366 to your computer and use it in GitHub Desktop.
Save manar007/299fb93a69b5d7703366 to your computer and use it in GitHub Desktop.
js bind simple implementation
Function.prototype.bind = function(context){
var that = this,
slicedArgs = Array.prototype.splice.call(arguments, 1),
bounded = function (){
var newArgs = slicedArgs.concat(Array.prototype.splice.call(arguments));
return that.apply(context,newArgs);
}
bounded.prototype = that.prototype;
return bounded;
};
@kalyansai99
Copy link

kalyansai99 commented Nov 24, 2017

@manar007 var newArgs = slicedArgs.concat(Array.prototype.splice.call(arguments)); is always returning empty array. We have to pass another argument inside splice.call like var newArgs = slicedArgs.concat(Array.prototype.splice.call(arguments, 0));

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