You are reading a single comment by @maze1980 and its replies.
Click here to read the full conversation.
-
Yes it's a bug.
arguments.length
is set to the number of arguments if the number of provided arguments is higher (and/or equal) to the number specified arguments in the function definition. But it is not set to the number of arguments if the number of provided arguments is smaller.As workaround define the function without arguments,
arguments.length
will be always correct.function foo(x,y) { console.log("arguments.length=" + arguments.length); //console.log("x=" + x); //console.log("y=" + y); //for ( var i=0; i < arguments.length; i++ ) { // console.log("typeof(arguments["+ i + "])=" + typeof(arguments[i])); // console.log("arguments["+ i + "]=" + arguments[i]); //} } function bar() { console.log("arguments.length=" + arguments.length); } foo(); foo(1); foo(1,2); foo(1,2,3); bar(); bar(1); bar(1,2); bar(1,2,3);
I was testing espruino on the Linux command line (while waiting for my boards to be shipped) and ran across this error. Is this a bug, or a feature?
The source was cloned from github and compiled on Ubuntu 16.04.6 LTS. I got the same error on an OS X build as well. It was built with the following commands:
I saw this post Functions with unknown amount of args. but I didn't get the same results.