C
Christopher T King
Reading through the ECMAScript spec, it seems that this code:
o = Object()
o['a'] = 5
o['b'] = 6
o['c'] = 7
for (var i in o) print(i);
should result in 'a', 'b', and 'c' being printed (not necessarily in that
order), and this is indeed the outcome. However, it also seems that this
code:
o = Array()
o[0] = 5
o[1] = 6
o[2] = 7
for (var i in o) print(i);
should result in 0, 1, and 2 being printed. However, this is not the
case: 5, 6, and 7 are instead printed.
I know these results are intuitively correct, but I can't find anything in
the ECMA spec making this distinction for Arrays. The for (i in o)
construction is defined to enumerate the properties of o, not the values
of those properties, and an array assignment o[n] = x is defined to assign
the value x to the property n of the object o.
Am I missing something in the spec, is the implementation I'm using (njs)
in error, or is this a discrepancy between JavaScript and ECMAScript?
Thanks in advance.
o = Object()
o['a'] = 5
o['b'] = 6
o['c'] = 7
for (var i in o) print(i);
should result in 'a', 'b', and 'c' being printed (not necessarily in that
order), and this is indeed the outcome. However, it also seems that this
code:
o = Array()
o[0] = 5
o[1] = 6
o[2] = 7
for (var i in o) print(i);
should result in 0, 1, and 2 being printed. However, this is not the
case: 5, 6, and 7 are instead printed.
I know these results are intuitively correct, but I can't find anything in
the ECMA spec making this distinction for Arrays. The for (i in o)
construction is defined to enumerate the properties of o, not the values
of those properties, and an array assignment o[n] = x is defined to assign
the value x to the property n of the object o.
Am I missing something in the spec, is the implementation I'm using (njs)
in error, or is this a discrepancy between JavaScript and ECMAScript?
Thanks in advance.