I have
var X={
method1 : function(){
A();
},
method2 : function(){
A();
},
}
function A(){
console.log('im from methodNAME of ObjNAME ');
}
How can I find out the name of the method and Object that the function is called from?
You can use
arguments.callerbut it’s not reliable:https://developer.mozilla.org/en/JavaScript/Reference/Functions_and_function_scope/arguments/caller
It has been replaced with https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/caller which seems to have reasonable browser support.