mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-09 15:34:05 +08:00
93 lines
5.7 KiB
HTML
93 lines
5.7 KiB
HTML
<article id="wikiArticle">
|
||
<div class="warning">.旧式生成器函数是一个SpiderMonkey专有特性,将在未来移除。从未来考虑,建议使用<a href="Reference/Operators/function*" title="function*关键字可以在表达式内部定义一个生成器函数。"><code>function* 表达式</code></a></div>
|
||
<div></div>
|
||
<p><strong><code>function</code></strong> 关键字可以用于在表达式中定义旧式的生成器函数。为使定义的函数为一个旧式的生成器函数,该函数的函数体中需要至少包含一个 <a href="Reference/Operators/yield" title="yield 关键字用来暂停和恢复一个生成器函数((function* 或遗留的生成器函数)。"><code>yield</code></a> 表达式。</p>
|
||
<h2 id="语法">语法</h2>
|
||
<pre><code class="language-javascript">function [<em>name</em>]([<em>param1</em>[, <em>param2[</em>, ..., <em>paramN</em>]]]) {
|
||
<em>statements</em>
|
||
}</code></pre>
|
||
<h3 id="参数">参数</h3>
|
||
<dl>
|
||
<dt><code>name</code></dt>
|
||
<dd>函数名。 该参数可以被省略, 这种情况下将创建一个<em>匿名函数 (anonymous)</em>. 此名字仅可在函数体内部引用。</dd>
|
||
<dt><code>paramN</code></dt>
|
||
<dd>将被传入此函数的一个参数。一个函数可以最多拥有255个参数。</dd>
|
||
<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">迭代器 (Iterators) 与生成器 (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>特性</th>
|
||
<th>Chrome</th>
|
||
<th>Firefox (Gecko)</th>
|
||
<th>Internet Explorer</th>
|
||
<th>Opera</th>
|
||
<th>Safari</th>
|
||
</tr>
|
||
<tr>
|
||
<td>基本支持</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>特性</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>基本支持</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/Statements/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 表达式</code></a></li>
|
||
<li><a href="Reference/Function" title="此页面仍未被本地化, 期待您的翻译!"><code>函数</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* 表达式</code></a></li>
|
||
<li><a href="Reference/Global_Objects/GeneratorFunction" title="GeneratorFunction构造器生成新的生成器函数 对象。在JavaScript中,生成器函数实际上都是GeneratorFunction的实例对象。"><code>生成器 (Generator) 函数</code></a></li>
|
||
<li><a href="/en-US/docs/Web/JavaScript/Guide/The_Iterator_protocol">迭代器 (Iterator) 协议 </a></li>
|
||
</ul>
|
||
</article> |