marijnh / Eloquent-JavaScript

The sources for the Eloquent JavaScript book
https://eloquentjavascript.net
2.99k stars 789 forks source link

Ch. 14 - Possible to loop over a NodeList via for/of #529

Closed simonaltrogge closed 3 years ago

simonaltrogge commented 3 years ago

In chapter 14 you mention here that it is not possible to loop over a Node‘s childNodes property using a for/of loop, since it is not a real array but a NodeList.

While it is true, that a NodeList is not an array, it is still iterable and therefore possible to be looped over via for/of according to the NodeList API on MDN.

If that was not already the case for the 2017 version of JS, excuse my comment on that matter.

Best regards and thanks a lot for your magnificent book!

marijnh commented 3 years ago

Good point—I wasn't aware of that. The DOM spec is separate from the JavaScript spec, so ES2017 says nothing about this, but it does look like this has been widely supported since 2016. Attached patch removes the paragraph.