# Weird prototype questions

**URL:** https://forum.kirupa.com/t/weird-prototype-questions/325867
**Category:** flash
**Created:** [November 9, 2011, 11:04am UTC](https://forum.kirupa.com/t/weird-prototype-questions/325867 "2011-11-09T11:04:39Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![md\_zoran](https://avatars.discourse-cdn.com/v4/letter/m/76d3ee/32.png) [@md\_zoran](https://forum.kirupa.com/u/md_zoran)
#### Post date: [November 9, 2011, 11:04am UTC](https://forum.kirupa.com/t/weird-prototype-questions/325867/1 "2011-11-09T11:04:39Z")

</div>

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 :

```auto
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 :

```auto
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 :

```auto
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 !
