关于这个问题 获取一个函数的数组 它的出现 function.length
属性。但对于接受 rest
参数或变量数的参数作为 function(...variable)
.
function func1() {}
console.log(func1.length);
// expected output: 0
function func2(...variable) {}
console.log(func2.length);
// expected output: 0
function func3(a) {}
console.log(func3.length);
// expected output: 1
如何知道该函数 func2
可以接受可变数量的参数吗?我不能仅仅通过使用 func2.length
因为它会说函数接受 0
而它 "可以 "接受至少0、1或更多的参数。