2017-02-17 47 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