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:

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! 8-)

Leave a Reply

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


− two = 0

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="">