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

27.12.2011, 03:59, "Boris Zbarsky" <bzbarsky@MIT.EDU>:
> 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?

Maybe you're right, and this is just sort of my perfectionism.


It would be nice to see comments from DOM4 editors now.

Thanks.

Received on Tuesday, 27 December 2011 00:58:29 UTC