Hello,
I’ve been playing with prototype a bit and I’ve noticed that either it isn’t as static as it should be or that some functions are protected from altering, or that in some cases the prototype actually extends a function.
For example, I was trying to modifiy the global trace function to output the current time of a trace action, something like this :
trace("lulu"); // output 12:48:17.286 lulu
I DID achieve something close to it, but it seems that I haven’t actually modified the global trace function, but rather it’s “_root” counterpart, like this :
MovieClip.prototype.trace = function(args)
{
var now:Date = new Date();
trace(now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds() + "." + now.getMilliseconds() + " " + args);
};
So now, if I call :
trace("lulu"); // output lulu
_root.trace("lulu"); // output 12:48:17.286 lulu
I’ve seen examples where “String” methods have been altered via “prototype” , and both String and trace are global… so… why one can be modified while the other cannot ?
I’ve tried putting Object instead of MovieClip, and even _global but it doesn’t work, the prototype is completely ignored.
IF the “trace” function can be modified, my question goes one step further… can I modify the “function” keyword somehow as to intercept any function calls ? I know, this one sounds a bit SciFi
But it would make a HUGE difference in debugging to have something like this :
function interceptor(someFunctionName,someFunctionArgs)
{
trace("I’ve just intercepted a call to "+someFunctionName);
call(someFunctionName,someFunctionArgs);
}
Also, intercepting the functions end would allow tracing a nice little call stack for thorough code execution investigation
Thanks in advance for any input you might have !