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

后端 未结 8 2125
佛祖请我去吃肉
佛祖请我去吃肉 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 05:05

    /function\s+(\[^\s\(]+)/
    

    What's with the backslash before [? I don't think you want a literal square bracket here. Without that it should work.

    Although I'd strongly recommend against anything to do with sniffing function name or especially sniffing caller function. Almost anything you might do using these hideous hacks will be better done using some combination of closures and lookups.

提交回复
热议问题