[Development] Why is "arguments" in a QML/JS function a map and not an array?

Knoll Lars Lars.Knoll at digia.com
Wed Aug 7 21:21:50 CEST 2013


Actually it's not. I just checked the specs (see
http://ecma-international.org/ecma-262/5.1/#sec-10.6), and the arguments
object is a JS object not a JS array.

This JS snippet

function foo() {    print(JSON.stringify(arguments))}
foo(1, 2, 3, 4)


gives exactly the same answer as below in any JS engine.

Cheers,
Lars

On 8/7/13 9:18 PM, "Knoll Lars" <Lars.Knoll at digia.com> wrote:

>Looks like a bug. Could you please create a Jira task for it?
>
>Thanks,
>Lars
>
>On 8/7/13 5:20 PM, "Milian Wolff" <mail at milianw.de> wrote:
>
>>Hey there!
>>
>>I noticed that the magic "arguments" is a map and not an array in QML/JS
>>functions. Is this intended? If so, why? If not, can it be changed or
>>would 
>>that break some code?
>>
>>See:
>>
>>Item {
>>  function foo() {
>>    console.log(JSON.stringify(arguments));
>>  }
>>  Component.onCompleted: {
>>    foo(1, 2, 3, 4);
>>  }
>>}
>>
>>actual output:
>>{"0":1,"1":2,"2":3,"3":4}
>>
>>expected output (which is also what "proper" javascript in a browser
>>does:
>>[1, 2, 3, 4]
>>
>>Bye
>>-- 
>>Milian Wolff
>>mail at milianw.de
>>http://milianw.de
>>_______________________________________________
>>Development mailing list
>>Development at qt-project.org
>>http://lists.qt-project.org/mailman/listinfo/development
>
>_______________________________________________
>Development mailing list
>Development at qt-project.org
>http://lists.qt-project.org/mailman/listinfo/development




More information about the Development mailing list