Non-standard. StopIteration object was a SpiderMonkey-specific feature and is removed in Firefox 58+. For future-facing usages, consider using for..of loops and the 迭代器协议 .

StopIteration object was used to tell the end of the iteration in the legacy iterator protocol. Do not use this ancient feature.

句法

StopIteration
				

描述

StopIteration is a part of legacy iterator protocol, and it will be removed at the same time as legacy iterator and legacy generator.

范例

StopIteration is thrown by Iterator .

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
				

Throwing StopIteration .

function f() {
  yield 1;
  yield 2;
  throw StopIteration;
  yield 3; // this is not executed.
}
for (var n in f()) {
  console.log(n);   // 1
                    // 2
}
				

规范

Non-standard. Not part of any current standards document

浏览器兼容性

Not supported. Used to be in Firefox in versions prior to Firefox 57.

另请参阅

元数据

  • 最后修改: