To get a function's name inside a function I can use this code:
function getmyname() {
var myName = arguments.callee.toString();
myName = myName.substr('function '.length);
myName = myName.substr(0, myName.indexOf('('));
alert(myName); // getmyname
}
however I need to run this a lot of times, so I'd rather use a function that does it, so it would look like:
function getmyname() {
alert(getfname()); // getmyname
}
so getfname() would get the name. How can this be done?
getfname()do with the name? Just return it? If so, why wouldn't you just reference the name in the first place?