返回函数的调用者
function test1(){
if(test1.caller == test2){
alert('test2 call me!');
}else if(test1.caller == test3){
alert('test3 call me!');
}else{
alert('Nobody call me!');
alert(test1.caller);
}
}
function test2(){
test1();
}
function test3(){
test1();
}
function main(){
test2();
test3();
}
main();
本文探讨了如何通过JavaScript函数的caller属性追踪并返回调用者的功能,详细展示了test1、test2和test3三个函数之间的调用关系,并通过main函数进行调用演示。
1292

被折叠的 条评论
为什么被折叠?



