- From: Michał Wadas <notifications@github.com>
- Date: Tue, 12 Jan 2016 02:12:27 -0800
- To: whatwg/dom <dom@noreply.github.com>
- Message-ID: <whatwg/dom/issues/147@github.com>
ES2015 introduces support for [iteration protocols](https://developer.mozilla.org/pl/docs/Web/JavaScript/Reference/Iteration_protocols). Iterators are objects with `.next` method which return object `{value: value, done: true/false}`. Iterables are objects with `Symbol.iterator` method that returns iterator. Making NodeIterator an iterator would be non-breaking change that will allow simple iteration of object using `for-of` loop or converting results to static array by spread operator. Simplest implementation would be: ``` NodeIterator.prototype.next = function() { const value = this.getNextNode(); return { value, done: !!val }; }; NodeIterator.prototype[Symbol.iterator] = function() { return this; } ``` I think real specification should include cloning "initial state" of NodeIterator to allow multiple iterations over the same NodeIterator. Similar logic can be applied to `XPathResult` objects that expose `iterateNext` method. Related [Firefox bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1238662). --- Reply to this email directly or view it on GitHub: https://github.com/whatwg/dom/issues/147
Received on Tuesday, 12 January 2016 10:13:03 UTC