Last active
July 25, 2016 17:05
-
-
Save DorkForce/15a65b4c188a495a1131 to your computer and use it in GitHub Desktop.
Self-Identify a function by name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getFunctionName() { | |
var re = /function (.*?)\(/ | |
var s = getFunctionName.caller.toString(); | |
var m = re.exec( s ) | |
return m[1]; | |
} | |
function me() { | |
console.log( getFunctionName() ); | |
} | |
me(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This hack/answer by James Hugard on StackOverflow is better than the adaptation I had written, since his does not rely on .callee ...It's still, as he said, a hack, but it's better!