W3C home > Mailing lists > Public > public-webapps@w3.org > April to June 2009

Re: Storage 'length' and enumeration

From: Sean Hogan <shogun70@westnet.com.au>
Date: Thu, 30 Apr 2009 14:52:08 +1000
Message-ID: <49F92E78.7020007@westnet.com.au>
To: Ian Hickson <ian@hixie.ch>
CC: John J Barton <johnjbarton@johnjbarton.com>, public-webapps@w3.org
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 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:31 GMT