Thanks for the clarification. Once put in context, I understand why you did that (it was just not mentioned in the initial post here).
FWIW, you can check the code behind this :
This is how I did it (it does use .caller ... but also toString
) but might not be that far from what you did too ...
It is used in a logger function so when calling the log function you don't need to mention the function (caller) and it is automatically mentioned in the log.
this.GetCaller = function() {
try { return arguments.callee.caller.caller.toString().match(/function\s+([^\s\(]+)/)[1]; }
catch (e) { return "<<Unknown caller function>>"; }
};
EDIT : This is in response to @cyilmaz clarification on the reasons of the function ... toString().