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.

Revision 1132781 of StopIteration

  • Revision slug: Web/JavaScript/Reference/Global_Objects/StopIteration
  • Revision title: StopIteration
  • Revision id: 1132781
  • Created:
  • Creator: fscholz
  • Is current revision? Yes
  • Comment lint

Revision Content

{{jsSidebar("Objects")}} {{deprecated_header}}
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

{{WhyNoSpecStart}}Non-standard. Not part of any current standards document.{{WhyNoSpecEnd}}

Browser compatibility

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{CompatNo}} {{CompatVersionUnknown}} {{CompatNo}} {{CompatNo}} {{CompatNo}}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatNo}} {{CompatNo}} {{CompatVersionUnknown}} {{CompatNo}} {{CompatNo}} {{CompatNo}}

See also

Revision Source

<div>{{jsSidebar("Objects")}} {{deprecated_header}}</div>

<div class="warning"><strong>Non-standard.</strong> The <code><strong>StopIteration</strong></code> object is a SpiderMonkey-specific feature. For future-facing usages, consider using <a href="/en-US/docs/Web/JavaScript/Reference/Statements/for...of">for..of</a> loops and the <a href="/en-US/docs/Web/JavaScript/Guide/The_Iterator_protocol">iterator protocol</a>.</div>

<p>The <code><strong>StopIteration</strong></code> object is used to tell the end of the iteration in the legacy iterator protocol.</p>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox">
StopIteration</pre>

<h2 id="Description">Description</h2>

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

<h2 id="Examples">Examples</h2>

<p><code>StopIteration</code> is thrown by <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator"><code>Iterator</code></a>.</p>

<pre class="brush: js">
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
</pre>

<p>Throwing <code>StopIteration</code>.</p>

<pre class="brush: js">
function f() {
  yield 1;
  yield 2;
  throw StopIteration;
  yield 3; // this is not executed.
}

for (var n in f()) {
  console.log(n);   // 1
                    // 2
}
</pre>

<h2 id="Specifications">Specifications</h2>

<p>{{WhyNoSpecStart}}Non-standard. Not part of any current standards document.{{WhyNoSpecEnd}}</p>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<div>{{CompatibilityTable}}</div>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Chrome for Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators">Iterators and Generators</a></li>
 <li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator">Iterator</a></li>
</ul>
Revert to this revision