简体   繁体   中英

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. Does this do what you want?

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

structure.A();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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