getCallingFunctionName()
is the important function here.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
function getCallingFunctionName() { var re = /function (.*?)\(/ var s = getFunctionName.caller.toString(); var m = re.exec( s ) return m[1]; } function myCurrentFunction(){ var func_name = getCallingFunctionName(); alert(func_name); //displays "myCurrentFunction" } myCurrentFunction(); |
Source: Can I get the name of the currently running function in JavaScript?