059_arguments.callee和arguments.callee.caller
生活随笔
收集整理的这篇文章主要介绍了
059_arguments.callee和arguments.callee.caller
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
1. arguments.callee指向函数本身。
2. arguments.callee.caller指向调用函数的函数。
3. 例子
3.1. 代码
<!DOCTYPE html> <html><head><title>arguments.callee和arguments.callee.caller</title></head><body><script type="text/javascript">// arguments.callee指向函数本身// arguments.callee.caller指向调用函数的函数function fun1(){console.log(arguments.callee);console.log(arguments.callee.caller);}function fun2(){console.log(arguments.callee);console.log(arguments.callee.caller);fun1();}function fun3(){console.log(arguments.callee);console.log(arguments.callee.caller);fun2();}fun3();// 利用arguments.callee生成学生唯一idvar tools = {id: function(){return (arguments.callee.id === undefined) ? (arguments.callee.id = 1001) : (++arguments.callee.id);}}function ClassPeople(firstName, lastName){this.id = tools.id();this.firstName = firstName;this.lastName = lastName;}ClassPeople.prototype.fullName = function(){return this.firstName + this.lastName;};var zhangsan = new ClassPeople('张', '三');console.log('id = ' + zhangsan.id + ', fullName = ' + zhangsan.fullName());var lisi = new ClassPeople('李', '四');console.log('id = ' + lisi.id + ', fullName = ' + lisi.fullName());// 利用arguments.callee.caller找到顶层调用函数function topFun1(){var c = arguments.callee.caller;do{console.log(c.name);}while(c = c.caller);}function topFun2(){topFun1();}function topFun3(){topFun2();}topFun3();</script></body> </html>3.2. 效果图
总结
以上是生活随笔为你收集整理的059_arguments.callee和arguments.callee.caller的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 091_类数组对象转为数组
- 下一篇: 003_推箱子-事件