问题
I know I can get the name of the current running function by using
arguments.callee.caller.name
But this does not work in Internet Explorer (any version). What's the correct cross-browser syntax? Does a workaround exist?
回答1:
Apart from the fact that arguments.callee is effectively being phased out and is completely absent in ECMAScript 5 strict mode, the main issue is that Function objects in IE do not have the name property. It is implemented in some browsers, notably Firefox and recent WebKit-based browsers, but is non-standard, and indeed there is no standardized way to get hold of a function name.
The only option this leaves you is trying to parse the name from the function's string representation, which is not a good idea. There's a (long) discussion here about it: http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/b85dfb2f2006c9f0.
回答2:
you can try this:
arguments.callee.caller.$name
as in IE it supports with $name
来源:https://stackoverflow.com/questions/6735931/does-internet-explorer-support-arguments-callee-name