W3C home > Mailing lists > Public > public-webapps@w3.org > July to September 2011

Re: [selectors-api] Return an Array instead of a static NodeList

From: Jonas Sicking <jonas@sicking.cc>
Date: Thu, 25 Aug 2011 16:17:45 -0700
Message-ID: <CA+c2ei8iHVL80L0h4Mh-ph7YApTHNh=9Ss-_LaT622jqp-SJMw@mail.gmail.com>
To: Aryeh Gregor <ayg@aryeh.name>
Cc: Julien Richard-Foy <julien@richard-foy.fr>, public-webapps@w3.org
On Thu, Aug 25, 2011 at 11:56 AM, Aryeh Gregor <ayg@aryeh.name> wrote:
>> And .push/.pop or other mutating functions wouldn't work.
>
> Right.  I'm only talking about the methods that are already generic
> and work with anything that looks like an Array: filter, forEach,
> every, etc.

.push and .pop are generic and work on anything that looks like an
Array. However they don't work on NodeList because NodeList isn't
mutable.

> On Thu, Aug 25, 2011 at 3:03 AM, Jonas Sicking <jonas@sicking.cc> wrote:
>> On Wed, Aug 24, 2011 at 11:47 PM, Julien Richard-Foy
>> <julien@richard-foy.fr> wrote:
>>> All mutable functions will work (forEach, map, etc.) and bring a better expressiveness to the code.
>>
>> Not if he 'this' object is a NodeList.
>
> This works fine right now:
>
> alert(
>  [].filter.call(document.querySelectorAll("*"), function(elem) {
> return elem.textContent.length > 6 })
>  .map(function(elem) { return elem.tagName })
>  .join(", ")
> );
>
> And I use that pattern a *lot*, but it's both verbose and extremely
> unintuitive.  Why can't that be just this?
>
> alert(
>  document.querySelectorAll("*")
>  .filter(function(elem) { return elem.textContent.length > 6 })
>  .map(function(elem) { return elem.tagName })
>  .join(", ")
> );

None of these are *mutable* functions.

/ Jonas
Received on Thursday, 25 August 2011 23:18:50 GMT

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