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

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,7 +2,7 @@
<div></div>
<p><code><strong>next</strong></code><strong><code>()</code></strong> 方法返回一个包含属性 <code>done</code><code>value</code> 的对象。该方法也可以通过接受一个参数用以向生成器传值。</p>
<h2 id="Syntax" name="Syntax">语法</h2>
<pre class="syntaxbox"><code><var>gen</var>.next(value)</code></pre>
<pre><code class="language-javascript"><code><var>gen</var>.next(value)</code></code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<dl>
<dt><code>value</code></dt>
@@ -23,7 +23,7 @@
<h2 id="示例">示例</h2>
<h3 id="Example:_Using_test" name="Example:_Using_test">使用 <code>next()方法</code></h3>
<p>下面的例子展示了一个简单的生成器, 以及调用 <code>next</code> 后方法的返回值:</p>
<pre class="brush: js">function* gen() {
<pre><code class="language-javascript">function* gen() {
yield 1;
yield 2;
yield 3;
@@ -34,10 +34,10 @@ g.next(); // "Object { value: 1, done: false }"
g.next(); // "Object { value: 2, done: false }"
g.next(); // "Object { value: 3, done: false }"
g.next(); // "Object { value: undefined, done: true }"
</pre>
</code></pre>
<h3 id="向生成器传值">向生成器传值</h3>
<p>在该示例中,调用 <code>next</code> 方法并传入了参数,请注意,首次调用 <code style="font-style: normal;">next</code> 方法时参数0被丢弃.</p>
<pre class="brush: js">/** gen函数运行解析
<pre><code class="language-javascript">/** gen函数运行解析
 * i=0 时传入参数(0)并将参数0赋给上一句yield的返回赋值由于没有上一句yield语句这步被忽略
 * 执行var val =100然后执行yield val此时g.next(i)返回{ value: 100, done: false }
* 然后console.log(i,g.next(i).value)打印出0 100
@@ -72,7 +72,7 @@ for(let i =0;i&lt;5;i++){
3 3
4
4 4
*/</pre>
*/</code></pre>
<p><img alt="向生成器传值的示例数据流向解析" src="https://mdn.mozillademos.org/files/15779/%E5%90%91%E7%94%9F%E6%88%90%E5%99%A8%E4%BC%A0%E5%80%BC.png"/></p>
<h2 id="Specifications" name="Specifications">规范</h2>
<table class="standard-table">

View File

@@ -2,7 +2,7 @@
<div></div>
<p><code><strong>return</strong></code><strong><code>()</code></strong> 方法返回给定的值并结束生成器。</p>
<h2 id="Syntax" name="Syntax">语法</h2>
<pre class="syntaxbox"><code><var>gen</var>.return(value)</code></pre>
<pre><code class="language-javascript"><code><var>gen</var>.return(value)</code></code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<dl>
<dt><code>value</code></dt>
@@ -13,7 +13,7 @@
<h2 id="示例">示例</h2>
<h3 id="Example:_Using_test" name="Example:_Using_test">使用 <code>return()</code></h3>
<p>以下例子展示了一个简单的生成器和 <code>return</code> 方法的使用.</p>
<pre class="brush: js">function* gen() {
<pre><code class="language-javascript">function* gen() {
yield 1;
yield 2;
yield 3;
@@ -24,14 +24,14 @@ var g = gen();
g.next(); // { value: 1, done: false }
g.return("foo"); // { value: "foo", done: true }
g.next(); // { value: undefined, done: true }
</pre>
</code></pre>
<h2 id="注意">注意</h2>
<p>如果生成器已经结束,<code>return(value) 会和上次的 </code>next() 一样value 为 undefined.</p>
<pre><code>function* gen() {yield 1;}
var g = gen();
console.log(g.next());//{ value: 1, done: false }
console.log(g.next());//{ value: undefined, done: true }
console.log(g.return(1)); //{ value: 1, done: true }</code></pre>
console.log(g.return(1)); //{ value: 1, done: true }</code></code></pre>
<h2 id="Specifications" name="Specifications">规范</h2>
<table class="standard-table">
<tbody>

View File

@@ -2,7 +2,7 @@
<div></div>
<p><code><strong>throw</strong></code><strong><code>()</code></strong> 方法用来向生成器抛出异常,并恢复生成器的执行,返回带有 <code>done</code><code>value</code> 两个属性的对象。</p>
<h2 id="Syntax" name="Syntax">语法</h2>
<pre class="syntaxbox"><code><var>gen</var>.throw(exception)</code></pre>
<pre><code class="language-javascript"><code><var>gen</var>.throw(exception)</code></code></pre>
<h3 id="参数">参数</h3>
<dl>
<dt><code>exception</code></dt>
@@ -23,7 +23,7 @@
<h2 id="示例">示例</h2>
<h3 id="Example:_Using_test" name="Example:_Using_test">使用 <code>throw()</code></h3>
<p>下面的例子展示了一个简单的生成器并使用 <span style="font-family: courier,andale mono,monospace;">throw方法</span>向该生成器抛出一个异常,该异常通常可以通过 <code><a href="/en-US/docs/Web/JavaScript/Reference/Statements/try...catch">try...catch</a></code> 块进行捕获.</p>
<pre class="brush: js">function* gen() {
<pre><code class="language-javascript">function* gen() {
while(true) {
try {
yield 42;
@@ -36,7 +36,7 @@
var g = gen();
g.next(); // { value: 42, done: false }
g.throw(new Error("Something went wrong")); // "Error caught!"
</pre>
</code></pre>
<h2 id="Specifications" name="Specifications">规范</h2>
<table class="standard-table">
<tbody>