简体   繁体   English

获取对象内部的函数名称

[英]Get name of function inside of object

Here is my code: 这是我的代码:

var structure = {
A: function() {
    this.B();
},

B: function() {
      console.log(arguments.callee.caller.toString());
}

}; };

Then I run: 然后我运行:

structure.A();

As you understand, I'm trying to get caller function name, but result is empty string. 如您所知,我正在尝试获取调用者函数名称,但结果是空字符串。 Are any ideas how to do that? 有什么想法要这样做吗?

I've added the function name A, and slightly changed the statement that gets the string to print. 我添加了函数名称A,并略微更改了获取要打印的字符串的语句。 Does this do what you want? 这是您想要的吗?

var structure = {
    A: function A() {
        this.B();
    },
    B: function() {
        console.log(arguments.callee.caller.name);
    }
}

structure.A();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM