- From: Aryeh Gregor <ayg@aryeh.name>
- Date: Thu, 25 Aug 2011 14:56:15 -0400
- To: Jonas Sicking <jonas@sicking.cc>
- Cc: Julien Richard-Foy <julien@richard-foy.fr>, public-webapps@w3.org
On Thu, Aug 25, 2011 at 2:33 AM, Jonas Sicking <jonas@sicking.cc> 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 <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(", ")
);
Likewise for all Array-like types, but NodeList is the most common.
Received on Thursday, 25 August 2011 18:57:15 UTC