Created
October 20, 2013 00:12
-
-
Save kgarfinkel/7063179 to your computer and use it in GitHub Desktop.
Javascript's 'call' re-implemented
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 call = function(fn, context) { | |
var args = Array.prototype.slice.call(arguments, 2).join(‘,’), | |
result; | |
context.fn = fn; | |
result = eval(“context.fn(“+ args +”)”); | |
delete this.fn; | |
return result; | |
}; |
Function.prototype.call = function () {
var args = [].slice.apply(arguments, [1]);
return this.apply(arguments[0], args);
};
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 7:
delete context.fn;