浅析 JavaScript caller 和callee区别
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml" > 3 <head> 4 <title>Caller And Callee</title> 5 <script type="text/javascript"> 6 window.onload = function () { 7 function demoCaller() { 8 if (demoCaller.caller) { 9 console.log("输出caller"); 10 console.log(demoCaller.caller.toString()); //输出 handleDemo函数 11 } else { 12 console.log('不存在demoCaller.caller'); 13 } 14 if (arguments.callee) { 15 console.log("输出callee"); 16 console.log(arguments.callee.toString()); //输出 demoCaller函数 17 } 18 if (demoCaller.caller && arguments.callee){ 19 console.log("同时调用caller and callee"); 20 console.log(arguments.callee.caller.toString()); //输出 handleDemo函数 21 } 22 } 23 function handleDemo() { 24 demoCaller(); 25 } 26 handleDemo(); 27 } 28 </script> 29 </head> 30 31 <body> 32 33 </body> 34 </html>