DorkForce
8/18/2015 - 4:20 PM

Self-Identify a function by name

Self-Identify a function by name

// does not work in strict mode

function getFunctionName() {
    var re = /function (.*?)\(/
    var s = getFunctionName.caller.toString();
    var m = re.exec( s )
    return m[1];
}

function me() {
    console.log( getFunctionName() );
}

me();