JavaScript – Faking Native Functions

The other day I kind of just wanted a reason to write a Gist and embed it on my site using this method. What I came up with was a quick way to make all functions appear to be native:
https://gist.github.com/9240810

Here is an example of what happens:

function alertAndReturn() {
  alert.apply(this, arguments);
  return arguments;
}

alert(alertAndReturn); // function alertAndReturn() { [native code] }
alert(function(){});   // function () { [native code] }

I have no clue when this would be useful in the real world but if you need it, here it is! šŸ˜Ž

Leave a Reply

Your email address will not be published. Required fields are marked *