Does Internet Explorer support arguments.callee.name?

别来无恙 提交于 2019-12-08 03:06:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!