For example:
(function() {
var proxied = window.eval;
window.eval = function() {
return proxied.apply(this, arguments);
};
})()
You can't. (There is a limited way of doing it, but it's quite limited and doesn't maintain the magic that bobince talks about.)
eval
isn't a real JavaScript function in at least one major implementation (IE's JScript, at least not through IE7; haven't tested the new IE8 version), so right off the bat you're going to run into trouble, because you won't be able to call the original via apply
(not that that really matters for eval
).
The recent ECMAScript 5 specification specifically disallows overriding eval
in strict mode (not that you're using strict mode there), which makes me suspect that there are very good reasons for not overriding it.