Non-standard. The
Iterator
function is a SpiderMonkey-specific feature, and will be removed at some point. For future-facing usages, consider using for..of loops and the iterator protocol.Summary
The Iterator
function returns an object which implements legacy iterator protocol and iterates over enumerable properties of an object.
Syntax
Iterator(object)
Parameters
object
- Object to iterate over properties.
Description
An overview of the usage is available on the Iterators and Generators page.
Methods
Iterator.prototype.next
- Returns next item in the
[property_name, property_value]
format. It throwsStopIteration
if there are no more items.
Examples
Iterating over properties of an object
var a = { x: 10, y: 20, }; var iter = Iterator(a); console.log(iter.next()); // ["x", 10] console.log(iter.next()); // ["y", 20] console.log(iter.next()); // throws StopIteration
Iterating over properties of an object with legacy destructuring for-in
statement
var a = { x: 10, y: 20, }; for (var [name, value] in Iterator(a)) { console.log(name, value); // x 10 // y 20 }
Specifications
Non-standard. Not part of any current standards document.
Browser compatibility
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | Нет | (Да) | Нет | Нет | Нет |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | Нет | Нет | (Да) | Нет | Нет | Нет |
See also
Метки документа и участники
Обновлялась последний раз:
fscholz,