callee和caller的作用和区别

callee和caller的作用和区别

callee的作用

callee是返回正在被执行的的function函数,也就是所指定的function 对象的正文。

 var a=function(){
      console.log(arguments.callee);
  }
  var b=function(){
      a()
  }
  b();
  ```
输出
```js
>ƒ(){
      console.log(arguments.callee);
  }

caller的作用

caller是返回一个对函数的引用,即该函数调用了在内部使用caller的函数

  var a=function(){
       console.log(a.caller);
   }
   var b=function(){
       a()
   }
   b();
   ```
输出
```js
>ƒ(){
      a()
   }

注意:全局中调用,返回null

 var a=function(){
      alert(a.caller);
  }//定义一个函数。里面输出a.caller
  a();//null,上面的例子一中,a函数是在b中调用的返回的是b函数,而这个例子是在全局中调用返回的是null
发布了15 篇原创文章 · 获赞 0 · 访问量 164

猜你喜欢

转载自blog.csdn.net/weixin_43310564/article/details/105464807