`
java-mans
  • 浏览: 11422203 次
文章分类
社区版块
存档分类
最新评论

javascript caller

 
阅读更多

返回函数的调用者

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


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics