web前端技术博客
您当前的位置:web前端 > JavaScript知识点

JavaScript arguments.callee

作者:只会切图的前端 发布时间:2021-02-22 10:04:31 浏览量:10

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();
// }

发表评论
验证码:
联系我
粤ICP备17092958号