JS - Function 之 Arguments

Arguments

函数的参数构成的数组

描述

只定义在函数体内,函数体内arugments指代Arguments对象,该对象是类数组对象,有数组属性可以当做数组使用,含有传入该函数的所有参数,arugments本质上是一个局部变量,在函数体内会自动声明并初始化改变量,仅在函数体内才指代Arguments对象,在全局代码中为undefined


Arguments

函数的为参数和其他属性

语法

  • arguments
  • arguments[n]

属性

callee

指代当前正在执行的函数。arguments.callee()

length

实际传递给函数的参数个数

描述

关联

Function

资源参考


Arguments.callee

当前正在执行的函数

语法

arguments.callee

描述

示例

// 匿名函数内部通过callee属性来引用匿名函数自身以便实现递归
const factorial = (x) => {
    if (x < 2) return 1;
    else return x * arguments.callee(x-1);
}
const y = factorial(5); // => 120 (5*4*3*2*1)
posted @ 2017-09-24 21:47  Jesonhu  阅读(163)  评论(0编辑  收藏  举报
Top