javascript - arguments.callee.toString() and arguments.callee.name does not return function name

后端 未结 8 2122
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-05 04:30

I\'m trying to get the name of the currently running function. From what I\'ve read, this should be possible using:

(arguments.callee.toString()).match(/func         


        
8条回答
  •  盖世英雄少女心
    2021-01-05 04:56

    The typical arguments.callee hacks don't work here because what you've done is assigned an anonymous function as the value for the object's 'testfunc' key. In this case the hacking even gets worse, but it can be done, as follows:

    var testobj = {
        testfunc: function(){
          for (var attr in testobj) {
                  if (testobj[attr] == arguments.callee.toString()) {
                      alert(attr);
                      break;
                    }
                }
        }
    }
    testobj.testfunc();
    

提交回复
热议问题