[whatwg] NodeList.forEach/map/filter still doesn't work

2014-01-04 Thread Kornel Lesiński


Everywhere on the web where NodeList.forEach() is mentioned, everybody  
agrees that's something that is expected to work, but doesn't. It's  
followed by a list of excuses why it doesn't work, as if it was a  
completely intractable problem that nobody can ever fix in any way  
whatsoever.


Can we please switch efforts from explaining why it's broken to actually  
fixing it?



It's sad that I can't use  
document.querySelector().filter().map().forEach() without patching  
prototypes myself. ES6 Array.from(), even with syntactic sugar, is a  
band-aid. NodeList.forEach() still doesn't work, but should.



I don't think anybody cares for NodeList.forEach/map/filter/etc to be  
real Array functions, so I'd love to see even a simplest fix like:


NodeList.prototype.map = function(...whatever) {
return Array.from(this).map(...whatever);
}

NodeList.prototype.forEach = function(...whatever) {
return Array.from(this).forEach(...whatever);
}

etc.

--
regards, Kornel Lesiński


Re: [whatwg] NodeList.forEach/map/filter still doesn't work

2014-01-04 Thread David Håsäther
On Sat, Jan 4, 2014 at 4:10 PM, Kornel Lesiński kor...@geekhood.net wrote:

 Everywhere on the web where NodeList.forEach() is mentioned, everybody
 agrees that's something that is expected to work, but doesn't. It's followed
 by a list of excuses why it doesn't work, as if it was a completely
 intractable problem that nobody can ever fix in any way whatsoever.

 Can we please switch efforts from explaining why it's broken to actually
 fixing it?

See http://dom.spec.whatwg.org/#collections:-elements

-- 
David Håsäther


Re: [whatwg] NodeList.forEach/map/filter still doesn't work

2014-01-04 Thread David Bruant

Le 04/01/2014 16:10, Kornel Lesiński a écrit :
I don't think anybody cares for NodeList.forEach/map/filter/etc to be 
real Array functions, so I'd love to see even a simplest fix like:


NodeList.prototype.map = function(...whatever) {
return Array.from(this).map(...whatever);
}

NodeList.prototype.forEach = function(...whatever) {
return Array.from(this).forEach(...whatever);
}
No need. Array.prototype.forEachfriends are generic on purpose so they 
can be applied to array-likes like NodeList.
Technically, we can have NodeList.prototype.forEach = 
Array.prototype.forEach (or rather Array.prototype in the NodeList 
instances prototype chain as currently speculatively spec'ed)
I imagine the problem if there is one will be a web compatibility one... 
as usual.


Relevant:
http://dom.spec.whatwg.org/#nodelist
http://code.google.com/p/chromium/issues/detail?id=229398
https://bugzilla.mozilla.org/show_bug.cgi?id=869376

Both Firefox and Chrome are already open to experiment it.
I imagine the only thing they need is the engineering time both to 
implement it and keep an eye open on their bug tracker to see if a 
website breaks because of this change, analyse, revert, do some 
evangelism to broken websites, retry, report back to standards for the 
bad news when people doing the experiment get tired of it.


I wish they were spending the time too. Other people would prefer to see 
the implementation of WebComponents prioritized.


How is your C++ and more importantly, what's the amount of time and 
patience you can put on evangelism? ;-)


David


Re: [whatwg] NodeList.forEach/map/filter still doesn't work

2014-01-04 Thread Boris Zbarsky

On 1/4/14 1:17 PM, David Bruant wrote:

I imagine the only thing they need is the engineering time both to
implement it


It's a one-line change in Firefox.


and keep an eye open on their bug tracker to see if a
website breaks because of this change


This is the problem.  Just watching for bug report is not really enough 
here...  It's hard to say whether this change can safely be made without 
breaking stuff.  :(


Note also that we can't really do this for HTMLCollection, only 
NodeList.  Which is enough for querySelector, of course.



How is your C++ and more importantly, what's the amount of time and
patience you can put on evangelism? ;-)


The latter, and not just evangelism, but compat testing, is what really 
matters.  Adding this stuff to NodeList in Gecko doesn't even need any 
C++ changes; it looks like this:


--- a/dom/webidl/NodeList.webidl
+++ b/dom/webidl/NodeList.webidl
@@ -12,3 +12,2 @@

+[ArrayClass]
 interface NodeList {

-Boris