如何知道哪个方法在javascript中调用其他方法

如何知道哪个方法在javascript中调用其他方法,javascript,jscript,Javascript,Jscript,假设我在jscript中有很多方法。。 方法1() 方法2() 方法3() 现在method1()和method2()是独立的。其中method3()由两个方法调用。我想知道从哪个方法调用method3()。method1()或method2()在这里都是简单的代码 function method1(){ method3('method1'); } function method2(){ method3('method2'); } function method3(method){

假设我在jscript中有很多方法。。 方法1()

方法2()

方法3()

现在method1()和method2()是独立的。其中method3()由两个方法调用。我想知道从哪个方法调用method3()。method1()或method2()在这里都是简单的代码

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

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

function method3(method){
  alert(method);
}
这里是简单的代码

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

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

function method3(method){
  alert(method);
}
试试这个

function method3() {
    alert("caller is " + arguments.callee.caller.toString());
}
试试这个

function method3() {
    alert("caller is " + arguments.callee.caller.toString());
}

以下是记录调用方方法名称的示例代码:

function method1(){
  method3();
}

function method2(){
  method3();
}

function method3(){
    console.log(method3.caller.name);
}
method1(); // method1
method2(); // method2

以下是记录调用方方法名称的示例代码:

function method1(){
  method3();
}

function method2(){
  method3();
}

function method3(){
    console.log(method3.caller.name);
}
method1(); // method1
method2(); // method2

@luiges90嗯,是的,看起来像是复制品。但是我找不到它,谢谢你的帮助:)@luiges90-hmmm是的,它看起来是复制品。但是我找不到它,谢谢你的帮助:)谢谢这是有帮助的谢谢这是有帮助的它也在警报中显示方法体,就像调用方是函数met1(){method3();}它说包参数。被调用方不存在它也在警报中显示方法体,就像调用方是函数met1(){method3();}它说package arguments.callee不存在