[thelist] Substitute for arguments.caller?

Marcus Bristav marcus.bristav at gmail.com
Thu Jun 21 14:50:39 CDT 2007

On 6/21/07, Lee Kowalkowski <lee.kowalkowski at googlemail.com> wrote:
> It's actually function.caller, e.g. function
> abc(){alert(abc.caller);}.  Although going via arguments.callee is the
> same difference, but arguments.callee only really exists to support
> recursive anonymous functions.

That's what I'm using. I have a getStackTrace(fn) that takes a
function pointer in the current execution context and recursively
loops upwards.

> Caller isn't defined in ECMAScript, and doesn't work in Opera
> (http://www.opera.com/docs/specs/js/ecma/) or Safari (so I'm told).

Yes, I noticed. And I have seen somewhere that Mozilla will remove
support for it as well (it might have been Brendan Eich that wrote
it). Too bad since it's really useful for debugging purposes in
environments where you cannot hook up with things such as Firebug.
Anyone that knows more about this?

> You can resort to passing in your functions as parameters, not nice.
> Or before you invoke a function, you can set its caller property, not
> nice either (it's read-only anyway except for where its not supported,
> then it'll work, but you'll also be able to set it to something
> wrong).

Agreed on the ugly part. Not to mention that it's a bit intrusive...

Humm... we're using our howngrown OO mechanism... I wonder if it would
be possible to wrap all the methods in the "classes" in some sort of
proxy-methods that can take care of that...

> Of course, unless Opera itself has some native stack-trace feature,
> but I can't find anything about that.

I'll try to find out. I have some connections at Opera so I might be
able to get something out of them... :)


More information about the thelist mailing list