• my test snippet:

    function abc(p1){
    console.log(arguments.length);
    }
    

    these tests are fine:

    abc(4);     // prints "1" .. ok
    abc(4,5,8); // prints "3" .. ok
    

    and here is the flaw:

    abc();     // prints "1" .. NOK - "0" expected (checked on browsers and node.js)
    

    as already mentioned - it's not critical, but some libraries written for node may fail in their arguments check.

  • found in 1v95 on EspruinoWIFI

  • Thanks for letting me know! I put a bug in for it here: https://github.com/espruino/Espruino/iss­ues/1321

    You probably gathered already but it's because you specified an argument p1. Espruino doesn't keep a second arguments array for the sake of saving memory, so it reconstructs the array when you ask for it.

    I think probably the sensible option for now is just to document this difference in the reference for arguments?

    I guess there should probably be a page for known differences to the ES5 spec, like the newline handling and lack of unicode

  • at least some hint in the API doc (http://www.espruino.com/Reference#l__glo­bal_arguments) would be fine.

  • Just done!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

arguments.length bug (not critical, but good to know)

Posted by Avatar for mrQ @mrQ

Actions