Skip to content

Instantly share code, notes, and snippets.

@DorkForce
Last active July 25, 2016 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DorkForce/15a65b4c188a495a1131 to your computer and use it in GitHub Desktop.
Save DorkForce/15a65b4c188a495a1131 to your computer and use it in GitHub Desktop.
Self-Identify a function by name
function getFunctionName() {
var re = /function (.*?)\(/
var s = getFunctionName.caller.toString();
var m = re.exec( s )
return m[1];
}
function me() {
console.log( getFunctionName() );
}
me();
@DorkForce
Copy link
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment