W3C home > Mailing lists > Public > public-script-coord@w3.org > April to June 2012

An iterable DOM

From: Jason Orendorff <jason.orendorff@gmail.com>
Date: Tue, 19 Jun 2012 16:01:52 -0500
Message-ID: <CAPh8+Zors4CH5k-1RABXy4HXoaS2+0Y=UoRfiWCwnrbVWD2r7g@mail.gmail.com>
To: public-script-coord <public-script-coord@w3.org>
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

This archive was generated by hypermail 2.3.1 : Wednesday, 8 May 2013 19:30:06 UTC