On the question Get a function's arity it is presented the function.length
property. But it does not work for function accepting rest
parameters or a variadic number of arguments as 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
How to know that the function func2
can accept a variable number of parameters? I cannot determine this just by using func2.length
because it will say the function accepts 0
parameters while it "can" accept at least 0, 1 or more.