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 707009 of Legacy generator function expression

  • Revision slug: Web/JavaScript/Reference/Operators/Legacy_generator_function
  • Revision title: Legacy generator function expression
  • Revision id: 707009
  • Created:
  • Creator: fscholz
  • Is current revision? No
  • Comment

Revision Content

The legacy generator function expression is a SpiderMonkey-specific feature, and will be removed at some point. For future-facing usages, consider using the {{jsxref("Operators/function*", "function* expression")}}.
{{jsSidebar("Operators")}}

Summary

The function keyword can be used to define a legacy generator function inside an expression. To make the function a legacy generator, the function body should contain at least one {{jsxref("Operators/yield", "yield")}} expression.

Syntax

function [name]([param1[, param2[, ..., paramN]]]) {
   statements
}

Parameters

name
The function name. Can be omitted, in which case the function is anonymous. The name is only local to the function body.
paramN
The name of an argument to be passed to the function. A function can have up to 255 arguments.
statements
The statements which comprise the body of the function. This should contain at least one {{jsxref("Operators/yield", "yield")}} expression.

Description

An overview of the usage is available on the Iterators and Generators page.

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 class="warning">
 The legacy generator function expression is a SpiderMonkey-specific feature, and will be removed at some point. For future-facing usages, consider using the {{jsxref("Operators/function*", "function* expression")}}.</div>
<div>
 <div>
  {{jsSidebar("Operators")}}</div>
</div>
<h2 id="Summary">Summary</h2>
<p>The <strong><code>function</code></strong> keyword can be used to define a legacy generator function inside an expression. To make the function a legacy generator, the function body should contain at least one {{jsxref("Operators/yield", "yield")}} expression.</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="syntaxbox">
function [<em>name</em>]([<em>param1</em>[, <em>param2[</em>, ..., <em>paramN</em>]]]) {
   <em>statements</em>
}</pre>
<h3 id="Parameters" name="Parameters">Parameters</h3>
<dl>
 <dt>
  <code>name</code></dt>
 <dd>
  The function name. Can be omitted, in which case the function is <em>anonymous</em>. The name is only local to the function body.</dd>
 <dt>
  <code>paramN</code></dt>
 <dd>
  The name of an argument to be passed to the function. A function can have up to 255 arguments.</dd>
 <dt>
  <code>statements</code></dt>
 <dd>
  The statements which comprise the body of the function. This should contain at least one {{jsxref("Operators/yield", "yield")}} expression.</dd>
</dl>
<h2 id="Description" name="Description">Description</h2>
<p>An overview of the usage is available on the <a href="/en-US/docs/JavaScript/Guide/Iterators_and_Generators" title="/en-US/docs/JavaScript/Guide/Iterators_and_Generators">Iterators and Generators</a> page.</p>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{CompatibilityTable}}</p>
<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" name="See_also">See also</h2>
<ul>
 <li>{{jsxref("Generator")}}</li>
 <li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/Legacy_generator_function">The legacy generator function</a></li>
 <li><a href="/en-US/docs/Web/JavaScript/Guide/The_legacy_Iterator_protocol">The legacy Iterator protocol</a></li>
 <li>{{jsxref("Operators/yield", "yield")}}</li>
 <li><a href="/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope" title="JavaScript/Reference/Functions_and_function_scope">Functions and function scope</a></li>
 <li>{{jsxref("Statements/function", "function")}}</li>
 <li>{{jsxref("Operators/function", "function expression")}}</li>
 <li>{{jsxref("Function")}}</li>
 <li>{{jsxref("Statements/function*", "function*")}}</li>
 <li>{{jsxref("Operators/function*", "function* expression")}}</li>
 <li>{{jsxref("GeneratorFunction")}}</li>
 <li><a href="/en-US/docs/Web/JavaScript/Guide/The_Iterator_protocol">The Iterator protocol</a></li>
</ul>
Revert to this revision