News for hackers. Stuff that matters.
Re:JavaScript Things I Wish I Knew Much Earlier In My Career by RyanMcGreal on Tuesday April 20, 2010 @11:57AM (#1279748)
>“Associative arrays” is a confusing name for objects.

And don't forget the `hasOwnProperty` test when iterating over the keys.

Re:JavaScript Things I Wish I Knew Much Earlier In My Career by nhebb on Tuesday April 20, 2010 @12:29PM (#1279852)
"Associative arrays" is a confusing name for objects

That line makes me think the author doesn't know what an associate array is.

Re:JavaScript Things I Wish I Knew Much Earlier In My Career by TallGuyShort on Tuesday April 20, 2010 @12:54PM (#1279925)
I think what he means is that it's not actually the array you're working with, so the name is misleading in this context. It's the underlying object. So if I have

var a : Array = []; a['property'] = 'value';

, then I'm setting a property of the object, not an element in the array. It works just as well with

var b : Object = {}; b['property'] = 'value';

Re:JavaScript Things I Wish I Knew Much Earlier In My Career by Silhouette on Tuesday April 20, 2010 @01:36PM (#1280054)
JavaScript doesn't make the same distinctions between numerically indexed arrays, string-indexed associative arrays and objects that you would see in most other languages. This explains a lot of the perceived oddities of JavaScript to programmers coming from backgrounds working with other programming languages, e.g., why calling sort() on an array of numbers doesn't do what you might expect and why the for-each loop in JavaScript iterates over indices rather than values.
Re:JavaScript Things I Wish I Knew Much Earlier In My Career by silentbicycle on Wednesday April 21, 2010 @09:55AM (#1282166)
The same is true of Lua, except it recognizes when you have consecutive integer keys and implements it as an actual array.