caller与callee

来源:互联网 发布:手机怎么备份所有数据 编辑:程序博客网 时间:2024/05/29 18:39

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]