Search code examples
javascriptjscript

how to know which method is calling other method in javascript


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()


Solution

  • Here it is simple code

    function method1(){
      method3('method1');
    }
    
    function method2(){
      method3('method2');
    }
    
    function method3(method){
      alert(method);
    }
    

    Reference