-
-
Save mahendrakalkura/06e478f6d9c199a4f2b2805057094247 to your computer and use it in GitHub Desktop.
Rewrite the bind method from scratch.
This file contains 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
var bind = function(context) { | |
var bindee = this; | |
var parameters = Array.prototype.slice.call(arguments, 1); | |
parameters = parameters.concat(Array.prototype.slice.call(arguments)); | |
var noop = function() {}; | |
var method = function() { | |
return bindee.apply(this instanceof noop? this: context, parameters); | |
}; | |
if (this.prototype) { | |
noop.prototype = this.prototype; | |
} | |
method.prototype = new noop(); | |
return method; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment