Files
uTools-Manuals/docs/javascript/Reference/Global_Objects/Function/isGenerator.html

28 lines
1.6 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.
<article id="wikiArticle">
<div> <div class="blockIndicator nonStandard nonStandardHeader">
<p><strong><span class="icon-only-inline" title="This API has not been standardized."><i class="icon-warning-sign"> </i></span> 非标准</strong><br/>
该特性是非标准的,请尽量不要在生产环境中使用它!</p>
</div></div>
<h2 id="概述">概述</h2>
<p>判断一个函数是否是一个<a href="/zh-cn/JavaScript/Guide/Iterators_and_Generators#Generators.3a_a_better_way_to_build_Iterators" title="zh-cn/Core JavaScript 1.5 Guide/Iterators and Generators#Generators.3a a better way to build Iterators">生成器</a>.</p>
<h2 id="语法">语法</h2>
<pre><code class="language-javascript"><code><var>fun</var>.isGenerator()</code></code></pre>
<h2 id="描述">描述</h2>
<p>该方法用来判断一个函数是否是一个<a href="/zh-cn/JavaScript/Guide/Iterators_and_Generators#Generators.3a_a_better_way_to_build_Iterators" title="zh-cn/Core JavaScript 1.5 Guide/Iterators and Generators#Generators.3a a better way to build Iterators">生成器</a>.</p>
<h2 id="例子">例子</h2>
<pre><code class="language-javascript">function f() {}
function* g() {
  yield 42;
}
console.log("f.isGenerator() = " + f.isGenerator());
console.log("g.isGenerator() = " + g.isGenerator());
</code></pre>
<p>上面代码的输出结果为</p>
<pre>f.isGenerator() = false
g.isGenerator() = true
</code></pre>
<h2 id="相关链接">相关链接</h2>
<ul>
<li><a href="/zh-cn/JavaScript/Guide/Iterators_and_Generators" title="zh-cn/Core JavaScript 1.5 Guide/Iterators and Generators">迭代器和生成器</a></li>
</ul>
</article>