uTools-Manuals/docs/javascript/Reference/Statements/Legacy_generator_function.html
2019-04-21 11:50:48 +08:00

98 lines
5.9 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<article id="wikiArticle">
<div class="warning">遗留的生成器函数是 SpiderMonkey 的特殊特性,会在未来的某个时刻被修改。为了以后的使用,考虑使用 <a href="Reference/Statements/function*" title="function* 这种声明方式(function关键字后跟一个星号会定义一个生成器函数 (generator function),它返回一个  Generator  对象。"><code>function*</code></a></div>
<div></div>
<p><strong>遗留的生成器函数语句 </strong>使用特殊参数声明遗留的生成器函数。</p>
<p>你也可以使用带有<code>functionBody</code>的构造<a class="new" href="Reference/函数" rel="nofollow" title="此页面仍未被本地化, 期待您的翻译!"><code>函数</code></a> ,至少一个 <a class="new" href="Reference/运算符/yield" rel="nofollow" title="此页面仍未被本地化, 期待您的翻译!"><code>yield</code></a> 表达式,以及<a class="new" href="Reference/运算符/Legacy_generator_function" rel="nofollow" title="此页面仍未被本地化, 期待您的翻译!">遗留的生成器函数表达式</a>来定义函数。</p>
<h2 id="语法">语法</h2>
<pre><code class="language-javascript">function <em>name</em>([<em>param</em>,[, <em>param</em>,[..., <em>param</em>]]]) {
[<em>statements</em>]
}
</code></pre>
<dl>
<dt><code>name</code></dt>
<dd>函数名。</dd>
</dl>
<dl>
<dt><code>param</code></dt>
<dd>传入函数的参数名一个函数最多有255个参数。</dd>
</dl>
<dl>
<dt><code>statements</code></dt>
<dd>构成函数体的语句。应该至少含有一个 <a href="Reference/Operators/yield" title="yield 关键字用来暂停和恢复一个生成器函数((function* 或遗留的生成器函数)。"><code>yield</code></a> 表达式。</dd>
</dl>
<h2 id="描述">描述</h2>
<p>用法概述可在 <a href="/en-US/docs/JavaScript/Guide/Iterators_and_Generators">迭代器和生成器</a>页面上查看。</p>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<p></p><div class="blockIndicator warning"><strong><a class="external" href="https://github.com/mdn/browser-compat-data" rel="noopener">We're converting our compatibility data into a machine-readable JSON format</a></strong>.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
<strong><a class="new" href="/zh-CN/docs/MDN/Contribute/Structures/Compatibility_tables" rel="nofollow">Find out how you can help!</a></strong></div>
<div class="htab">
<a id="AutoCompatibilityTable" name="AutoCompatibilityTable"></a>
<ul>
<li class="selected"><a>Desktop</a></li>
<li><a>Mobile</a></li>
</ul>
</div><p></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><span style="color: #f00;">未实现</span></td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td><span style="color: #f00;">未实现</span></td>
<td><span style="color: #f00;">未实现</span></td>
<td><span style="color: #f00;">未实现</span></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><span style="color: #f00;">未实现</span></td>
<td><span style="color: #f00;">未实现</span></td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td><span style="color: #f00;">未实现</span></td>
<td><span style="color: #f00;">未实现</span></td>
<td><span style="color: #f00;">未实现</span></td>
</tr>
</tbody>
</table>
</div>
<h2 id="参考">参考</h2>
<ul>
<li><a href="Reference/Global_Objects/Generator" title="生成器对象是由一个 generator function 返回的,并且它符合可迭代协议和迭代器协议。"><code>Generator</code></a></li>
<li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Legacy_generator_function">遗留的函数生成器表达式</a></li>
<li><a href="/en-US/docs/Web/JavaScript/Guide/The_legacy_Iterator_protocol">遗留的迭代器协议</a></li>
<li><a href="Reference/Operators/yield" title="yield 关键字用来暂停和恢复一个生成器函数((function* 或遗留的生成器函数)。"><code>yield</code></a></li>
<li><a href="/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope">函数和函数作用域</a></li>
<li><a href="Reference/Statements/function" title="函数声明定义一个具有指定参数的函数。"><code>function</code></a></li>
<li><a href="Reference/Operators/function" title="function 关键字可以用来在一个表达式中定义一个函数。"><code>function expression</code></a></li>
<li><a href="Reference/Function" title="此页面仍未被本地化, 期待您的翻译!"><code>Function</code></a></li>
<li><a href="Reference/Statements/function*" title="function* 这种声明方式(function关键字后跟一个星号会定义一个生成器函数 (generator function),它返回一个  Generator  对象。"><code>function*</code></a></li>
<li><a href="Reference/Operators/function*" title="function*关键字可以在表达式内部定义一个生成器函数。"><code>function* expression</code></a></li>
<li><a href="Reference/Global_Objects/GeneratorFunction" title="GeneratorFunction构造器生成新的生成器函数 对象。在JavaScript中生成器函数实际上都是GeneratorFunction的实例对象。"><code>GeneratorFunction</code></a></li>
<li><a href="/en-US/docs/Web/JavaScript/Guide/The_Iterator_protocol">迭代器协议</a></li>
</ul>
</article>