2017-02-17 115 views
-3

我是javascript的新手,是否有可能在函数本身中使用函数getName在Java脚本中获取函数名称

function test(){ 
    //how can i get current function name here. 
} 
+2

为什么......?另外,如果你正在执行'test',函数是不是'test' ...? – Li357

+0

你想解决什么问题? –

+0

或http://stackoverflow.com/questions/3178892/get-function-name-in-javascript –

回答

-1

您可以很容易地在JAVASCRIPT中获得当前的函数名称。

例如:

function chet(){ 
    console.log(arguments.callee.name); 
    } 
+2

谢谢@amit你已经解决了我的问题。 – keshav

+1

为什么downvote?有用 ? –

+1

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments/callee – Shilly