An iterable DOM

WebIDL should add explicit support for iteration. Many programming
languages have language-level syntactic support for iteration (Python,
Ruby, Java, C++), and it's coming soon to ECMAScript.

ECMAScript is adding a "for...of" loop. Example:
  var languages = ['Python', 'Java', 'C++', 'ES'];
  for (var x of languages)
      alert(x + " has a nice for loop");

Details here:
  http://wiki.ecmascript.org/doku.php?id=harmony:iterators

Arrays are iterable, because there's a new built-in
Array.prototype.iterator method. Many DOM objects should be iterable
too. Certainly those with indexed properties and .length:

  for (var elt of document.querySelectorAll(".post:not(.grouchy)"))
      addUnicorns(elt);

Possibly also dictionaries and DOM iterators.

Thoughts?

-j

Received on Tuesday, 19 June 2012 21:02:25 UTC