W3C home > Mailing lists > Public > public-script-coord@w3.org > October to December 2011

Re: What type should .findAll return

From: Yehuda Katz <wycats@gmail.com>
Date: Sat, 12 Nov 2011 00:17:11 -0800
Message-ID: <CAMFeDTX=4kMchERxwpiXcAZ7bWtYM0cAw2kcS9=m7crKV5in5w@mail.gmail.com>
To: Jonas Sicking <jonas@sicking.cc>
Cc: "Tab Atkins Jr." <jackalmage@gmail.com>, Rick Waldron <waldron.rick@gmail.com>, Allen Wirfs-Brock <allen@wirfs-brock.com>, Boris Zbarsky <bzbarsky@mit.edu>, "public-script-coord@w3.org" <public-script-coord@w3.org>, public-webapps <public-webapps@w3.org>
I'd like to see this thing smell like a normal Array, plus useful node
methods:

1. It should have at least all of the non-mutating Array methods on
> it. Possibly the mutating methods too if we allow the returned object
> to be mutable.
>

Agreed.


> 2. It should have a object on the prototype chain where we can insert
> functions that are specifically useful for lists of nodes. Examples
> include .find/.findAll/.matchesSelector/.remove/.addEventListener
>

It would be nice if it also had getElementsBy*. This object (ElementList?)
could be a beachhead allowing us to add more useful functionality to lists
of elements in the browser over time.

Since this is a totally new API, we're also not bound by the API for
individual nodes, so we could use shorter names, like .is() for
matchesSelector() and .on() for addEventListener.


> 3. It would be good if it had the Array prototype object on it's
> prototype chain so that if Array.prototype was extended, it would
> affect this object too.
>

Absolutely.


> 4. The object will *not* be live since live results from selector
> matching is slow.


Agreed.

Yehuda Katz
(ph) 718.877.1325


On Fri, Nov 11, 2011 at 6:04 PM, Jonas Sicking <jonas@sicking.cc> wrote:

> On Fri, Nov 11, 2011 at 5:59 PM, Tab Atkins Jr. <jackalmage@gmail.com>
> wrote:
> > On Fri, Nov 11, 2011 at 5:52 PM, Rick Waldron <waldron.rick@gmail.com>
> wrote:
> >> Right, but I'm saying: why create yet more "stuff" in the DOM?
> >>
> >>  findAll will return a "NodeArray" while querySelectorAll and friends
> return static and live NodeLists? No thanks.
> >
> > I'm not sure what you would prefer.  Make findAll return an Array? (We
> > miss out on a *lot* of cool and useful stuff we could do.)  Make
> > findAll return immutable live NodeLists? (Ditto, but for different
> > reasons.)  Change qSA to return a NodeArray or Array? (Would be nice,
> > but probably not doable for compat reasons.)
>
> Actually, if we add .item to NodeArray then it's entirely possible
> that we can make qSA return a NodeArray. I'm not entirely convinced
> that's worth it though.
>
> / Jonas
>
>
Received on Saturday, 12 November 2011 08:18:00 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 8 May 2013 19:30:04 UTC