Js中caller和callee的区别

1 :caller 返回一个调用当前函数的引用 如果是由顶层调用的话 则返回null

  var callerTest = function() {
       console.log(callerTest.caller) ;  
 } ;
  function a() {
       callerTest() ;   
 }
 a() ;//输出function a() {callerTest();}
 callerTest() ;//输出null 

2 :callee 返回一个正在被执行函数的引用 (这里常用来递归匿名函数本身 但是在严格模式下不可行)

 callee是arguments对象的一个成员 表示对函数对象本身的引用 它有个length属性(代表形参的长度)

 var c = function(x,y) {
         console.log(arguments.length,arguments.callee.length,arguments.callee)
  } ;
 c(1,2,3) ;//输出3 2 function(x,y) {console.log(arguments.length,arguments.callee.length,arguments.callee)} 
原文地址:https://www.cnblogs.com/princeness/p/11664916.html