juan_gandhi: (Default)
[personal profile] juan_gandhi

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.

Date: 2008-11-11 04:45 pm (UTC)
From: [identity profile] ivan-gandhi.livejournal.com
Well, at least we should be happy that JS4 standard was not adopted. It was turning JS into a strictly-typed language.

Date: 2008-11-11 05:57 pm (UTC)
nine_k: A stream of colors expanding from brain (Default)
From: [personal profile] nine_k
Sure.
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.)

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

July 2025

S M T W T F S
  12345
6789 1011 12
131415 1617 1819
20212223242526
2728 2930 31  

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 1st, 2025 06:24 am
Powered by Dreamwidth Studios