Re: Storage 'length' and enumeration

Ian Hickson wrote:
>
> There are lots of objects that are not arrays (or should not be rendered 
> as arrays) and yet have length. Collections, TimeRanges, <select> 
> elements, Window objects, History, CanvasPixelArrays, etc.
>
>   
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.


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.

Received on Thursday, 30 April 2009 04:53:11 UTC