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_推箱子-事件