by rfw · 10y ago · 0 comments
It seems that it also extends to full expressions on the right-hand side of ::, so you can even do, for using Array operations over things that look like arrays but not quite:
document.querySelectorAll('p')::([].map)(f)
instead of: [].map.call(document.querySelectorAll('p'), f)
(replace [].map with Array.prototype.map if it feels less gross) [...document.querySelectorAll('p')].map(f)
In the future, NodeList could extend Array which would make these workarounds redundant. Extending Array was made possible by ES6.Anyhow, I think having some kind of extension methods would be great.
It would break the web, unfortunately. (We've experimented with NodeList.prototype.__proto__ being Array.prototype instead of Object.prototype and it breaks sites, and ES6's extends notion implies that.)
for(const el of document.querySelectorAll('p')) {}
Why have the overhead of a callback to begin with. It reads SO much better as well. (~R∊R∘.×R)/R←1↓ιR