JavaScript: Get current function name

getCallingFunctionName() is the important function here.

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?

Related Posts:

Posts that may be related to "JavaScript: Get current function name":

Catzie

A Filipino programmer and baker. When I have time to spare, I blog, play video games, watch series (usually anime), cook dishes, draw, or spend a little time with pets. When I have the rare luxury of time, I get to travel and record song covers too! Running small-time online dessert shops Cookies PH and Catzie's Cakery.

Leave a Reply

Your email address will not be published. Required fields are marked *