Comment by troupo
20 hours ago
> with `someNodeList[Symbol.iterator]().map(…)` or `Iterator.from(someNodeList).map(…)`
I always feel like clawing my eyes out with most of the DOM APIs, or workarounds for them :)
20 hours ago
> with `someNodeList[Symbol.iterator]().map(…)` or `Iterator.from(someNodeList).map(…)`
I always feel like clawing my eyes out with most of the DOM APIs, or workarounds for them :)
[Symbol.iterator] is more the for/of API (protocol, more accurately) than a DOM API. It's an improvement today that the DOM APIs pick up niceties like direct [Symbol.iterator] in addition to Iterator methods like entries().
It's nice that there is syntax sugar for [Symbol.iterator] in both for/of and also the spread operator/deconstruction/rest operator (things like [...someNodeList] and const [item1, item2, ...rest] = nodeList).
In theory, the only missing piece is syntax sugar for Iterator.from() if you wanted to direct chain any iterable to the iterator helperrs. But in practice, that's also part of why the explicit iterator methods like entries() already exist and those are surprisingly well implemented (and have been for a while), including on NodeList.