W3C home > Mailing lists > Public > www-dom@w3.org > October to December 2011

Re: toArray() method for array-like DOM list objects

From: Boris Zbarsky <bzbarsky@MIT.EDU>
Date: Mon, 26 Dec 2011 18:59:33 -0500
Message-ID: <4EF90A65.1080207@mit.edu>
To: "Marat Tanalin | tanalin.com" <mtanalin@yandex.ru>
CC: www-dom@w3.org
On 12/26/11 6:20 PM, Marat Tanalin | tanalin.com wrote:
>>     var obj1 = new Array();
>>     obj1[0] = "x";
>>     obj1["z"] = "y";
>>
>>     var obj2 = new Object();
>>     obj2[0] = "x";
>>     obj2["z"] = "y";
>>     Object.defineProperty(obj2, "length",
>>                           { value: 2, writable: true,
>>                             configurable: true, enumerable: false });
>>
>> What are the exact differences between obj1 and obj2 as long as you
>> don't plan to modify them (so you're just reading data you were passed)?
>
> Using Array object (instead of pure Object) as associative array is usually considered bad practice because Array's length property does not reflect items with nonnumeric keys.

Neither does the "length" property of the Object above.

Seriously, I think you're trying to read in distinctions that are not 
quite there.

>> I think you have a pretty confused understanding of how Arrays work in
>> ECMAScript.  They're just another associative-array-like object whose
>> prototype happens to be Array.prototype, and with some special behavior
>> around changes to the "length" property.
>
> That "some special behavior" does matter, I think.

Why, for cases when you only plan to read the array or object or 
whatever, not modify it?

-Boris
Received on Tuesday, 27 December 2011 00:00:05 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:14:09 GMT