W3C home > Mailing lists > Public > whatwg@whatwg.org > April 2010

[whatwg] HTMLCollection and HTMLAllCollection suggestion

From: David Flanagan <david@davidflanagan.com>
Date: Sat, 03 Apr 2010 21:58:15 -0700
Message-ID: <4BB81C67.4060208@davidflanagan.com>
Perry Smith wrote:
> HTMLCollection has a namedItem method that returns either null or one 
> object. [1]
> 
> HTMLAllCollection has a namedItem method that returns either null, one 
> object, or a collection of objects. [2]
> 
> I'm a Rails freak and one of the things that they do which I love is foo 
> returns an item and foos returns a list of items.  The unconscious 
> benefit of this I believe is huge.
> 
> My suggestion is to have namedItem always return either null or 1 object.
> 
> And have namedItem*s* always return a collection.  We can debate whether 
> it is better to return null or an empty collection.  I prefer the latter 
> myself.  Then I can always feed it to an iterator.
> 
> [1] http://www.whatwg.org/specs/web-apps/current-work/multipage/urls.html#htmlcollection-0
> [2] http://www.whatwg.org/specs/web-apps/current-work/multipage/urls.html#htmlallcollection-0

Perry,

But no one actually invokes namedItem()--they just use a regular 
property access expression on an HTMLAllCollection.  namedItem() is left 
over from the strange days when the W3C was specifying Java APIs for 
working with XML instead of JavaScript APIs for HTML!

	David Flanagan
Received on Saturday, 3 April 2010 21:58:15 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:22 UTC