语法高亮,滚动条美化,设置页面调整

This commit is contained in:
fofolee
2019-04-19 02:41:09 +08:00
parent 1e8f76c000
commit 359d29ee0b
1590 changed files with 12328 additions and 11441 deletions

View File

@@ -2,14 +2,14 @@
<div> </div>
<p><strong>生成器</strong>对象是由一个 <a href="Reference/Statements/function*" title="function* 这种声明方式(function关键字后跟一个星号会定义一个生成器函数 (generator function),它返回一个  Generator  对象。">generator function</a> 返回的,并且它符合<a href="Reference/Iteration_protocols#iterable">可迭代协议</a><a href="Reference/Iteration_protocols#iterator">迭代器协议</a></p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox">function* gen() {
<pre><code class="language-javascript">function* gen() {
yield 1;
yield 2;
yield 3;
}
let g = gen();
// "Generator { }"</pre>
// "Generator { }"</code></pre>
<h2 id="方法">方法</h2>
<dl>
<dt><a href="Reference/Global_Objects/Generator/next" title="next() 方法返回一个包含属性 done 和 value 的对象。该方法也可以通过接受一个参数用以向生成器传值。"><code>Generator.prototype.next()</code></a></dt>
@@ -21,7 +21,7 @@ let g = gen();
</dl>
<h2 id="示例">示例</h2>
<h3 id="一个无限迭代器">一个无限迭代器</h3>
<pre class="brush: js">function* idMaker(){
<pre><code class="language-javascript">function* idMaker(){
let index = 0;
while(true)
yield index++;
@@ -35,7 +35,7 @@ console.log(gen.next().value);
// 1
console.log(gen.next().value);
// 2
// ...</pre>
// ...</code></pre>
<h2 id="传统的生成器对象">传统的生成器对象</h2>
<p>Firefox (SpiderMonkey) 在 <a href="/en-US/docs/Web/JavaScript/New_in_JavaScript/1.7">JavaScript 1.7</a> 中也实现了一个较早版本的生成器,其中函数声明中的星号(*)不是必需的 (只需在函数体中使用<code style="font-style: normal;">yield</code> 关键字)。但是,旧式生成器已弃用。不要使用它们;他们将被删除  (<a class="external" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1083482" rel="noopener" title="FIXED: Remove SpiderMonkey support for JS1.7 legacy generators">bug 1083482</a>)。</p>
<h3 id="传统的生成器方法">传统的生成器方法</h3>
@@ -50,7 +50,7 @@ console.log(gen.next().value);
<dd>向生成器抛出错误. 与ES2015 生成器对象的<span style="font-family: courier,andale mono,monospace;">throw()方法对应</span>.</dd>
</dl>
<h3 id="旧生成器对象示例">旧生成器对象示例</h3>
<pre class="brush: js">function fibonacci() {
<pre><code class="language-javascript">function fibonacci() {
var a = yield 1;
yield a * 2;
}
@@ -61,7 +61,7 @@ console.log(it.next()); // 1
console.log(it.send(10)); // 20
console.log(it.close()); // undefined
console.log(it.next()); // throws StopIteration (as the generator is now closed)
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>