callee、caller详解

在学习JavaScript的一些总结和经验,供大家参考和学习,同时也欢迎大家参与讨论。

arguments对象

arguments对象不是一个 Array 。它是类似于数组(类数组),但除了 长度之外没有任何数组属性。
例如,它没有 pop 方法、sort方法。但是它可以被转换为一个真正的数组:

1
2
3

let args = Array.prototype.slice.call(arguments);
let args = [].slice.call(arguments);

callee

callee是arguments对象的一个属性、用来指向当前执行的函数。

1
2
3
4
5

function foo(){
console.log(arguments);
}
foo();

arguments.callee

caller

arguments.caller 指向调用当前函数的函数。

1
2
3
4
5
6
7
8
9

function foo1(){
console.log(arguments.callee.caller);
}
function foo2(){
foo1();
}
foo1();
foo2();

arguments.callee.caller


文章标题: callee、caller详解
文章作者: 王奕聪,QQ:1301842163
许可协议: 知识共享许可协议
©署名-非商用-相同方式共享 4.0