I want to do the opposite of Get JavaScript function-object from its name as a string?
That is, given:
function foo()
{}
function bar(callback)
{
var name = ???; // how to get "foo" from callback?
}
bar(foo);
How do I get the name of the function behind a reference?
If you can’t use
myFunction.namethen you can:Or for modern browsers that don’t support the
nameproperty (do they exist?) add it directly: