Re: Storage 'length' and enumeration

Ian Hickson wrote:
> On Thu, 30 Apr 2009, Sean Hogan wrote:
>   
>> I'm not sure about all those objects, but my (incomplete) testing of
>> HTML*Collections indicates that when accessed using array notation:
>>    object[index]; where index < object.length
>> they behave as a readonly array. Which has the fortuitous by-product of
>> allowing the object to work with Array.forEach(), etc.
>>
>> Storage objects have a length property and can be accessed with array 
>> notation. They look like they should work with Array generic methods... 
>> and they do... except they aren't reliable if you use numeric keys... 
>> but they don't even give an error message.
>>     
>
> They work the same way as a collection does when one of the items in a 
> collection has a name that's numeric, e.g. document.images with an <img> 
> element whose name="" attribute has the value 0.
>
>   
>> I would suggest one of:
>> 1. When accessed as an array they are treated as a readonly array. i.e. MUST
>> use getItem(), setItem() for numeric keys
>> 2. Treat it as an associative array. Change the name of the length property.
>>     
>
> Storage works exactly like a collection in this respect; the values from 0 
> to length-1 override the names.
>
>   
Ok, I think you're confirming that Storage objects will work 
consistently with Array generic methods; the callback receiving a key 
into the Storage object.

I obviously haven't been following this thread accurately.

Received on Thursday, 30 April 2009 07:02:09 UTC