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

On Thu, Aug 25, 2011 at 2:33 AM, Jonas Sicking <> wrote:
> That works, but what is the advantage?

The same advantage as having those methods work for Array.  :)
They're useful for lots of stuff.

> 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.

On Thu, Aug 25, 2011 at 3:03 AM, Jonas Sicking <> wrote:
> On Wed, Aug 24, 2011 at 11:47 PM, Julien Richard-Foy
> <> 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:

  []"*"), 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?

  .filter(function(elem) { return elem.textContent.length > 6 })
  .map(function(elem) { return elem.tagName })
  .join(", ")

Likewise for all Array-like types, but NodeList is the most common.

Received on Thursday, 25 August 2011 18:57:15 UTC