How to get function name in strict mode [proper way]

后端 未结 2 411
耶瑟儿~
耶瑟儿~ 2021-01-13 08:33

arguments.callee unfortunatelly deprecated, and using it throws an error in \"strict mode\".

Is there any new proper(standard) alternative for getting functi

2条回答
  •  心在旅途
    2021-01-13 09:03

    If you use Node.js there is a useful package exactly for this problem: caller-id

    var callerId = require('caller-id');
    
    function foo() {
        bar();
    }
    
    function bar() {
        var callerName = callerId.getData().functionName; /* 'foo' */
    }
    

提交回复
热议问题