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

  • Revision slug: Web/JavaScript/Reference/Statements/Legacy_generator_function
  • Revision title: Legacy generator function
  • Revision id: 784257
  • Created:
  • Creator: fscholz
  • Is current revision? No
  • Comment lint

Revision Content

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

The legacy generator function statement declares legacy generator functions with the specified parameters.

You can also define functions using the {{jsxref("Function")}} constructor with functionBody and at least one {{jsxref("Operators/yield", "yield")}} expression, and a {{jsxref("Operators/Legacy_generator_function", "legacy generator function expression", "", 1)}}.

Syntax

function name([param,[, param,[..., param]]]) {
   [statements]
}
name
The function name.
param
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 is a SpiderMonkey-specific feature, and will be removed at some point. For future-facing usages, consider using {{jsxref("Statements/function*", "function*")}}.</div>

<div>{{jsSidebar("Statements")}}</div>

<p>The <strong>legacy generator function statement</strong> declares legacy generator functions with the specified parameters.</p>

<p>You can also define functions using the {{jsxref("Function")}} constructor with <code>functionBody</code> and at least one {{jsxref("Operators/yield", "yield")}} expression, and a {{jsxref("Operators/Legacy_generator_function", "legacy generator function expression", "", 1)}}.</p>

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

<pre class="syntaxbox">
function <em>name</em>([<em>param</em>,[, <em>param</em>,[..., <em>param</em>]]]) {
   [<em>statements</em>]
}
</pre>

<dl>
 <dt><code>name</code></dt>
 <dd>The function name.</dd>
</dl>

<dl>
 <dt><code>param</code></dt>
 <dd>The name of an argument to be passed to the function. A function can have up to 255 arguments.</dd>
</dl>

<dl>
 <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">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">See also</h2>

<ul>
 <li>{{jsxref("Generator")}}</li>
 <li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Legacy_generator_function">The legacy generator function expression</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