Skip to content

Instantly share code, notes, and snippets.

@kgarfinkel
Created October 20, 2013 00:12
Show Gist options
  • Save kgarfinkel/7063179 to your computer and use it in GitHub Desktop.
Save kgarfinkel/7063179 to your computer and use it in GitHub Desktop.
Javascript's 'call' re-implemented
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;
};
@decaylala
Copy link

Line 7: delete context.fn;

@jjenzz
Copy link

jjenzz commented Mar 26, 2014

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