1

consider i have many methods in jscript.. method1()

method2()

method3()

Now method1() and method2() are independent. where method3() is called by both the methods. I want to know from which method method3() is getting called. either method1() or method2()

Mani Deep
  • 1,298
  • 2
  • 17
  • 33

3 Answers3

1

Here it is simple code

function method1(){
  method3('method1');
}

function method2(){
  method3('method2');
}

function method3(method){
  alert(method);
}

Reference

Naveen Kumar Alone
  • 7,536
  • 5
  • 36
  • 57
0

try this.

function method3() {
    alert("caller is " + arguments.callee.caller.toString());
}
Naveen Kumar Alone
  • 7,536
  • 5
  • 36
  • 57
sudhansu63
  • 6,025
  • 4
  • 39
  • 52
0

Here is the sample code which logs the Caller method name :

function method1(){
  method3();
}

function method2(){
  method3();
}

function method3(){
    console.log(method3.caller.name);
}
method1(); // method1
method2(); // method2
Niranjan Borawake
  • 1,628
  • 13
  • 20