- From: Jonas Sicking <jonas@sicking.cc>
- Date: Thu, 25 Aug 2011 16:17:45 -0700
- 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 UTC