arguments doesn't have properties?

35 views
Skip to first unread message

Andy S

unread,
Jun 16, 2015, 9:12:13 AM6/16/15
to js...@googlegroups.com
Why does the following work in FF and Chrome JS console:

> function x(a,b,c) { for (p in arguments) console.log(p) }

> x(1,2,3)
0
1
2


but not in JSDB:

js> function x(a,b,c) { for (p in arguments) writeln(p) }
js> x(1,2,3)


And yet, the below works:

js> function x(a,b,c) { writeln(arguments[0]) }
js> x(1,2,3)
1

Andy S

unread,
Jun 16, 2015, 9:12:13 AM6/16/15
to js...@googlegroups.com
Why does the following fail in JSBD:


js>function x(a,b,c) { for (p in arguments) writeln(p) }
js>x("a","b","c")


when it seems to work in FF and Chrome:


>function x(a,b,c) { for (p in arguments) console.log(p) }
>x("a","b","c")
0
1
2

But strangely enough, accessing 'arguments' individually does work:

js>function x(a,b,c) { for (p in arguments) writeln(p); writeln(arguments[0] }
js>x("a","b","c")
a


gilado

unread,
Jun 16, 2015, 10:07:00 AM6/16/15
to js...@googlegroups.com

Shanti Rao

unread,
Jun 16, 2015, 11:20:10 AM6/16/15
to js...@googlegroups.com, sy....@gmail.com
JSDB uses an older version of the Spidermonkey engine, in which arguments isn't really an object, it's just a hack in the interpreter with a length property and a [] accessor.

Sorry.


On Tuesday, June 16, 2015 at 6:12:13 AM UTC-7, Andy S wrote:

Andy S

unread,
Jun 18, 2015, 9:48:52 AM6/18/15
to js...@googlegroups.com
On Tuesday, June 16, 2015 at 11:20:10 PM UTC+8, Shanti Rao wrote:

> JSDB uses an older version of the Spidermonkey engine, in which arguments isn't
> really an object, it's just a hack in the interpreter with a length property and a [] accessor.
>
> Sorry.
 
Thanks for the clarification.

On Tuesday, June 16, 2015 at 10:07:00 PM UTC+8, gilado wrote:

I believe Shanti's explanation is correct.  arguments is not an object in the
JS engine version used in JSDB. 

for..in works with for an object not just Arrays.

js>x = { "prop1":1, "prop2":2 }
[object Object]

js>for (p in x) writeln(p)
prop1
prop2

Reply all
Reply to author
Forward
0 new messages