【发布时间】:2012-12-07 07:17:10
【问题描述】:
可能重复:
Can I get the name of the currently running function in javascript?
我想从函数本身获取函数名。
Javascript:
Cube : {
profile : {
edit : function(){
// Get function Path Cube.edit Here
alert(arguments.callee.name); // Not Working
}
}
}
【问题讨论】:
-
你可以直接命名你的函数:
edit: function edit() { ... } -
@Osiris 我解决了这个问题。但我没有得到我的答案。
alert(arguments.callee.name);不适用于上述代码示例。 -
@elclanrs:这会在 IE8 和更早版本上创建 two functions。
-
@elclanrs 我在问题中编辑我的代码。请看一下。现在我想得到 profile.edit()
-
@JavedAkhtar:更改代码只是添加一个进一步的对象层是没有意义的,它根本不会改变问题,只会使现有答案在编辑之前看起来很奇怪。
标签: javascript