您现在的位置:首页 >> 前端 >> 内容

caller与callee

时间:2017/7/12 17:13:03 点击:

  核心提示:1. callee在函数执行时,调用arguments.callee, 返回函数本身的引用function printHello() {console.log(hello jupiter!);cons...

1. callee

在函数执行时,调用arguments.callee, 返回函数本身的引用

function printHello() {
  console.log('hello jupiter!');
  console.log(arguments.callee);
}

printHello();

输出

hello jupiter!
[Function: printHello]

2. caller

在函数执行时,调用fn.caller,返回调用函数的引用

function printHello() {
  console.log('hello jupiter!');
  console.log(arguments.callee.caller);
  console.log(printHello.caller);  // 与上一句效果相同
}

function callHello() {
  printHello();
}

callHello();

输出

hello jupiter!
[Function: callHello]
[Function: callHello]

Tags:CA AL LL LE 
作者:网络 来源:Marshall00