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 16:58:04 +1000
Message-ID: <49F94BFC.4050502@westnet.com.au>
To: Ian Hickson <ian@hixie.ch>
CC: "John J. Barton" <johnjbarton@johnjbarton.com>, Boris Zbarsky <bzbarsky@MIT.EDU>, public-webapps@w3.org
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

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 18:12:53 UTC