Closed
Bug 869376
Opened 12 years ago
Closed 9 years ago
Nodelist should be ArrayClass
Categories
(Core :: DOM: Core & HTML, enhancement)
Core
DOM: Core & HTML
Tracking
()
RESOLVED
WONTFIX
People
(Reporter: mike.maccana, Unassigned)
References
Details
Attachments
(1 file)
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31
Steps to reproduce:
I want to iterate over a Nodelist
Actual results:
I had to run:
NodeList.prototype.forEach = Array.prototype.forEach
Or equivalent code. This (or something very similar) has become one of the first thing any programmer who wants to use Vanilla JS does.
Expected results:
It would be reasonable for browsers to provide NodeList.prototype.forEach for us. This would:
- eliminate boilerplate code required to do simple things with .querySelectorAll() or .children() results
- be consistent with other iterables most notable Arrays.
Updated•12 years ago
|
Severity: normal → enhancement
Component: Untriaged → DOM
OS: Mac OS X → All
Product: Firefox → Core
Hardware: x86 → All
Comment 1•12 years ago
|
||
Please file a spec bug or discuss it on public-webapps.
https://www.w3.org/Bugs/Public/enter_bug.cgi?product=WebAppsWG&component=DOM
http://lists.w3.org/Archives/Public/public-webapps/
It doesn't make much sense to implement it only on Firefox.
Comment 2•12 years ago
|
||
The right mailing list for DOM is www-dom, not public-webapps, and the spec already has [ArrayClass] on NodeList, which would add forEach in particular.
WebKit tried to implement it but hit issues on Google properties; arv is planning to try it again in Blink. If that succeeds, we'll probably implement it too.
Comment 3•12 years ago
|
||
All [ArrayClass] means is that you chain up to Array.prototype instead of Object.prototype, right?
That's pretty trivial to implement if people want to experiment with it. I'll put up a patch, just for posterity.
That said, is there a reason HTMLCollection is not [ArrayClass]? Worries about issues with named props? It does meant that .children will NOT have the arrayclass behavior.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Flags: needinfo?(annevk)
Updated•12 years ago
|
Summary: Nodelist should come with a .forEach() out of the box → Nodelist should come with a .forEach() out of the box (implement [ArrayClass] support)
Comment 4•12 years ago
|
||
Currently only childNodes and mutation records use NodeList.
The concern with HTMLCollection is indeed named props. Overall concern is compatibility. If we're happy to experiment...
(One longer term plan is to make sure that the new .find and .findAll return objects that do have this and are also more extensible than HTMLCollection and NodeList.)
Flags: needinfo?(annevk)
Comment 5•12 years ago
|
||
I should note that [ArrayClass] leads to some pretty bizarre behavior, per specs. For example, this:
var x = document.querySelectorAll("*");
var y = x.concat();
gives us a "y" that's an Array of length 1, and y[0] === x.
Comment 6•12 years ago
|
||
> Currently only childNodes and mutation records use NodeList.
And querySelector*, fwiw.
Comment 7•12 years ago
|
||
Updated•12 years ago
|
Assignee: nobody → bzbarsky
Updated•12 years ago
|
Assignee: bzbarsky → nobody
| Reporter | ||
Comment 8•12 years ago
|
||
(In reply to Boris Zbarsky (:bz) from comment #7)
> Created attachment 749328 [details] [diff] [review]
> Implement support for [ArrayClass]. r=??????. This patch still needs tests
Thanks very much for this Boris and co.
As Boris and I mentioned earlier, NodeLists are used in querySelector() / querySelectorAll() which are typically the first steps of library-free selection and DOM manipulation. Not having to patch in NodeList.prototype.forEach() would be massively helpful to any web developer interested in 'Vanilla JS'.
Updated•12 years ago
|
Keywords: dev-doc-needed
Comment 9•12 years ago
|
||
I spun off basic ArrayClass support into bug 892609.
Summary: Nodelist should come with a .forEach() out of the box (implement [ArrayClass] support) → Nodelist should be ArrayClass
Comment 10•11 years ago
|
||
This needs @@isConcatSpreadable support to have a hope of being web-compatible.
Depends on: 1041586
Comment 11•9 years ago
|
||
Wontfix in favor of bug 1290636; we have not managed to convince anyone else to do this, so...
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → WONTFIX
Updated•9 years ago
|
Keywords: dev-doc-needed
| Assignee | ||
Updated•7 years ago
|
Component: DOM → DOM: Core & HTML
You need to log in
before you can comment on or make changes to this bug.
Description
•