I was always curious is there any possibility to overload function literal, something like you can do with Function:
var test=Function;
Function=function(arg)
{
alert('test');
return test(arg);
}
var b=Function("alert('a')");
var c=Function("alert('x')");
b();
c();
Of course you can guess that this is nice way of debugging whole project. However any effort I made here goes for nothing.
Question for you experts is:
You're terminology is off: Function()
is the function constructor , whereas function() {...}
is a function literal .
And no, I don't think there's a portable way to do this, but there might be for old versions of Firefox: If I remember correctly, it once was possible to use with() {...}
to shadow the built-in constructor functions and Firefox would use the new ones even for literals.
This seems to work no longer:
var overload = {
Object : function() {}
};
overload.Object.prototype.foo = 'bar';
with(overload) {
document.writeln(new Object().foo);
document.writeln({}.foo);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.