Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

StopIteration

我們的志工尚未將此文章翻譯為 正體中文 (繁體) 版本。加入我們,幫忙翻譯!

Deprecated
This feature has been removed from the Web standards. Though some browsers may still support it, it is in the process of being dropped. Avoid using it and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

Non-standard. The StopIteration object is a SpiderMonkey-specific feature. For future-facing usages, consider using for..of loops and the iterator protocol.

The StopIteration object is used to tell the end of the iteration in the legacy iterator protocol.

Syntax

StopIteration

Description

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

Examples

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
}

Specifications

Non-standard. Not part of any current standards document.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support No support (Yes) No support No support No support
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support No support No support (Yes) No support No support No support

See also

文件標籤與貢獻者

 此頁面的貢獻者: fscholz, arai
 最近更新: fscholz,