iterating NodeList's
When JavaScript got array iterators like Array.prototype.forEach
I was extremely happy. But not for long. What made me just happy was the inability to do even document.links.forEach()
. Don't even mention the likes of getElementsByName
. That's when I started using the inelegant things like toArray
. Though I liked better to add forEach
in NodeList.prototype
or to monkey-patch querySelectorAll
. But now EcmaScript 2015 (aka EcmaScript 6) comes to the resque!
The new version should support following approach: for (var link of document.links) {}
. You can even get something like your favourite closure-effect of a callback using for (let link of document.links) {}
. And finally there's an elegant way to convert any array-like object to a proper array: [...document.links].filter()
.
I don't know about you, but I really look forward to the new features. By the way, I think the best articles on EcmaScript 6 are in the blog of Dr. Alex Rauschmayer.