more javascript
Nov. 9th, 2008 06:44 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
for (var idx in ['uno', 'dos', 'tres']) {
println (typeof idx + " " + idx);
}
string 0
string 1
string 2
Explanation
JavaScript does not have arrays. Period. What it has is an imitation of arrays. Namely, objects that have keys (all keys in objects are strings) that represent numbers.
var x = ['uno', 'dos', 'tres'];
x[3.999] = 'casi cuatro';
x[-1] = 'minus uno';
println(x.length);
for (var idx in x) {
println(idx + "->" + x[idx]);
}
(try it on testbed)
You can pass anything as an index; it is converted to a string.
So, I guess, iterables or streams or continuations should be implemented in JavaScript without using arrays.
no subject
Date: 2008-11-11 04:45 pm (UTC)no subject
Date: 2008-11-11 05:57 pm (UTC)JS is conceptually fine, on the lower level. But its syntax is not the best of breed. (I wonder if JS could have a documented "VM" level for plugging in different syntaxes.)