Closed
Description
NodeList
interface is defined as iterable in DOM4, but by design it cannot be directly used in for-of loop because we cannot declare it as iterable in ES5.
Suggestion
Introduce a ES5-compatible way to declare iterable interfaces (Similar to what discussed in #2862)
// WebIDL-like way
interface NodeList {
iterable<Node>
}
// extends-like way
interface NodeList iterable<Node> {}
iterable<T>
in ES6 mode will work as a shorthand of [Symbol.iterator](): IterableIterator<T>
but in ES5 mode will just make an internal flag to be allowed in for-of loop.
// NodeList is marked as iterable,
// it has .length property and index signature for ES5 emit, so all good
for (let node of document.querySelectorAll("...")) {
}
This will make it work both on ES5 and ES6 without changing emit.