JavaScript arguments.callee
arguments.callee是指向正在执行的函数指针。
可以用于函数的递归调用
如递归阶乘函数:
function factorial(a) {
if (a <= 1) {
return 1;
} else {
return a * arguments.callee(a - 1);
}
}
注意:严格模式下使用arguments.callee会导致错误
Uncaught TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them
arguments.caller是指向调用当前函数的函数引用。
function fun1(){
fun2();
}
function fun2(){
console.log(arguments.callee.caller);
}
fun1();
//输出
// ƒ fun1() {
// fun2();
// }