diff options
Diffstat (limited to 'files/zh-cn/web/javascript/reference/statements')
15 files changed, 98 insertions, 106 deletions
diff --git a/files/zh-cn/web/javascript/reference/statements/break/index.html b/files/zh-cn/web/javascript/reference/statements/break/index.html index 8714bc8c29..25d8964e32 100644 --- a/files/zh-cn/web/javascript/reference/statements/break/index.html +++ b/files/zh-cn/web/javascript/reference/statements/break/index.html @@ -33,18 +33,18 @@ translation_of: Web/JavaScript/Reference/Statements/break <p>下面的函数里有个 <code>break</code> 语句,当 <code>i</code> 为 3 时,会中止 {{jsxref("Statements/while", "while")}} 循环,然后返回 3 * <code>x</code> 的值。</p> -<pre class="brush: js notranslate"><code class="language-js"><span class="keyword token">function</span> <span class="function token">testBreak</span><span class="punctuation token">(</span>x<span class="punctuation token">)</span> <span class="punctuation token">{</span> - <span class="keyword token">var</span> i <span class="operator token">=</span> <span class="number token">0</span><span class="punctuation token">;</span> - - <span class="keyword token">while</span> <span class="punctuation token">(</span>i <span class="operator token"><</span> <span class="number token">6</span><span class="punctuation token">)</span> <span class="punctuation token">{</span> - <span class="keyword token">if</span> <span class="punctuation token">(</span>i <span class="operator token">==</span> <span class="number token">3</span><span class="punctuation token">)</span> <span class="punctuation token">{</span> - <span class="keyword token">break</span><span class="punctuation token">;</span> - <span class="punctuation token">}</span> - i <span class="operator token">+</span><span class="operator token">=</span> <span class="number token">1</span><span class="punctuation token">;</span> - <span class="punctuation token">}</span> - - <span class="keyword token">return</span> i <span class="operator token">*</span> x<span class="punctuation token">;</span> -<span class="punctuation token">}</span></code></pre> +<pre class="brush: js notranslate"><code class="language-js">function testBreak(x) { + var i = 0; + + while (i < 6) { + if (i == 3) { + break; + } + i += 1; + } + + return i * x; +}</code></pre> <h3 id="break_in_switch_statements">break in switch statements</h3> diff --git a/files/zh-cn/web/javascript/reference/statements/continue/index.html b/files/zh-cn/web/javascript/reference/statements/continue/index.html index dfea4a3be3..ce08e7f444 100644 --- a/files/zh-cn/web/javascript/reference/statements/continue/index.html +++ b/files/zh-cn/web/javascript/reference/statements/continue/index.html @@ -43,15 +43,15 @@ translation_of: Web/JavaScript/Reference/Statements/continue <p>下述例子展示了一个在<code>i</code> 为 3时执行<code>continue</code> 语句的 {{jsxref("Statements/while", "while")}} 循环。因此,<code>n</code> 的值在几次迭代后分别为 1, 3, 7 和 12 .</p> -<pre class="brush: js language-js"><code class="language-js">i <span class="operator token">=</span> <span class="number token">0</span><span class="punctuation token">;</span> -n <span class="operator token">=</span> <span class="number token">0</span><span class="punctuation token">;</span> -<span class="keyword token">while</span> <span class="punctuation token">(</span>i <span class="operator token"><</span> <span class="number token">5</span><span class="punctuation token">)</span> <span class="punctuation token">{</span> - i<span class="operator token">++</span><span class="punctuation token">;</span> - <span class="keyword token">if</span> <span class="punctuation token">(</span>i <span class="operator token">===</span> <span class="number token">3</span><span class="punctuation token">)</span> <span class="punctuation token">{</span> - <span class="keyword token">continue</span><span class="punctuation token">;</span> - <span class="punctuation token">}</span> - n <span class="operator token">+</span><span class="operator token">=</span> i<span class="punctuation token">;</span> -<span class="punctuation token">}</span></code></pre> +<pre class="brush: js language-js"><code class="language-js">i = 0; +n = 0; +while (i < 5) { + i++; + if (i === 3) { + continue; + } + n += i; +}</code></pre> <h3 id="使用带_label_的_continue">使用带 label 的 continue</h3> @@ -61,51 +61,51 @@ n <span class="operator token">=</span> <span class="number token">0</span><span <p>参考 {{jsxref("Statements/label", "label")}} 。</p> -<pre class="brush: js language-js"><code class="language-js"><span class="keyword token">var</span> i <span class="operator token">=</span> <span class="number token">0</span><span class="punctuation token">,</span> - j <span class="operator token">=</span> <span class="number token">8</span><span class="punctuation token">;</span> +<pre class="brush: js language-js"><code class="language-js">var i = 0, + j = 8; -checkiandj<span class="punctuation token">:</span> <span class="keyword token">while</span> <span class="punctuation token">(</span>i <span class="operator token"><</span> <span class="number token">4</span><span class="punctuation token">)</span> <span class="punctuation token">{</span> - console<span class="punctuation token">.</span><span class="function token">log<span class="punctuation token">(</span></span><span class="string token">"i: "</span> <span class="operator token">+</span> i<span class="punctuation token">)</span><span class="punctuation token">;</span> - i <span class="operator token">+</span><span class="operator token">=</span> <span class="number token">1</span><span class="punctuation token">;</span> +checkiandj: while (i < 4) { + console.log("i: " + i); + i += 1; - checkj<span class="punctuation token">:</span> <span class="keyword token">while</span> <span class="punctuation token">(</span>j <span class="operator token">></span> <span class="number token">4</span><span class="punctuation token">)</span> <span class="punctuation token">{</span> - console<span class="punctuation token">.</span><span class="function token">log<span class="punctuation token">(</span></span><span class="string token">"j: "</span><span class="operator token">+</span> j<span class="punctuation token">)</span><span class="punctuation token">;</span> - j <span class="operator token">-</span><span class="operator token">=</span> <span class="number token">1</span><span class="punctuation token">;</span> - <span class="keyword token">if</span> <span class="punctuation token">(</span><span class="punctuation token">(</span>j <span class="operator token">%</span> <span class="number token">2</span><span class="punctuation token">)</span> <span class="operator token">==</span> <span class="number token">0</span><span class="punctuation token">)</span> - <span class="keyword token">continue</span> checkj<span class="punctuation token">;</span> - console<span class="punctuation token">.</span><span class="function token">log<span class="punctuation token">(</span></span>j <span class="operator token">+</span> <span class="string token">" is odd."</span><span class="punctuation token">)</span><span class="punctuation token">;</span> - <span class="punctuation token">}</span> - console<span class="punctuation token">.</span><span class="function token">log<span class="punctuation token">(</span></span><span class="string token">"i = "</span> <span class="operator token">+</span> i<span class="punctuation token">)</span><span class="punctuation token">;</span> - console<span class="punctuation token">.</span><span class="function token">log<span class="punctuation token">(</span></span><span class="string token">"j = "</span> <span class="operator token">+</span> j<span class="punctuation token">)</span><span class="punctuation token">;</span> -<span class="punctuation token">}</span></code></pre> + checkj: while (j > 4) { + console.log("j: "+ j); + j -= 1; + if ((j % 2) == 0) + continue checkj; + console.log(j + " is odd."); + } + console.log("i = " + i); + console.log("j = " + j); +}</code></pre> <p>输出:</p> -<pre class="brush: js language-js"><code class="language-js"><span class="string token">"i: 0"</span> -<span class="comment token"> +<pre class="brush: js language-js"><code class="language-js">"i: 0" + // start checkj -</span><span class="string token">"j: 8"</span> -<span class="string token">"7 is odd."</span> -<span class="string token">"j: 7"</span> -<span class="string token">"j: 6"</span> -<span class="string token">"5 is odd."</span> -<span class="string token">"j: 5"</span><span class="comment token"> +"j: 8" +"7 is odd." +"j: 7" +"j: 6" +"5 is odd." +"j: 5" // end checkj -</span> -<span class="string token">"i = 1"</span> -<span class="string token">"j = 4"</span> -<span class="string token">"i: 1"</span> -<span class="string token">"i = 2"</span> -<span class="string token">"j = 4"</span> +"i = 1" +"j = 4" + +"i: 1" +"i = 2" +"j = 4" -<span class="string token">"i: 2"</span> -<span class="string token">"i = 3"</span> -<span class="string token">"j = 4"</span> +"i: 2" +"i = 3" +"j = 4" -<span class="string token">"i: 3"</span> -<span class="string token">"i = 4"</span> -<span class="string token">"j = 4"</span></code></pre> +"i: 3" +"i = 4" +"j = 4"</code></pre> <h2 id="规范">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/statements/debugger/index.html b/files/zh-cn/web/javascript/reference/statements/debugger/index.html index e078482767..2a54579002 100644 --- a/files/zh-cn/web/javascript/reference/statements/debugger/index.html +++ b/files/zh-cn/web/javascript/reference/statements/debugger/index.html @@ -19,10 +19,10 @@ translation_of: Web/JavaScript/Reference/Statements/debugger <p>下面的例子演示了一个包含 debugger 语句的函数,当函数被调用时,会尝试调用一个可用的调试器进行调试。</p> -<pre class="brush:js language-js" style="padding: 1em 0px 1em 30px; font-size: 14px; white-space: normal; color: rgb(77, 78, 83);"><code class="language-js" style="direction: ltr; white-space: pre;"><span class="keyword token" style="color: #0077aa;">function</span> <span class="function token" style="color: #dd4a68;">potentiallyBuggyCode<span class="punctuation token" style="color: #999999;">(</span></span><span class="punctuation token" style="color: #999999;">)</span> <span class="punctuation token" style="color: #999999;">{</span> - <span class="keyword token" style="color: #0077aa;">debugger</span><span class="punctuation token" style="color: #999999;">;</span> - <span class="comment token" style="color: #708090;"> // do potentially buggy stuff to examine, step through, etc. -</span><span class="punctuation token" style="color: #999999;">}</span></code></pre> +<pre class="brush:js language-js" style="padding: 1em 0px 1em 30px; font-size: 14px; white-space: normal; color: rgb(77, 78, 83);"><code class="language-js" style="direction: ltr; white-space: pre;">function potentiallyBuggyCode() { + debugger; + // do potentially buggy stuff to examine, step through, etc. +}</code></pre> <p>当 debugger 被调用时, 执行暂停在 debugger 语句的位置。就像在脚本源代码中的断点一样。</p> diff --git a/files/zh-cn/web/javascript/reference/statements/do...while/index.html b/files/zh-cn/web/javascript/reference/statements/do...while/index.html index bd3fb46473..714c0e807e 100644 --- a/files/zh-cn/web/javascript/reference/statements/do...while/index.html +++ b/files/zh-cn/web/javascript/reference/statements/do...while/index.html @@ -10,7 +10,7 @@ translation_of: Web/JavaScript/Reference/Statements/do...while <div>{{jsSidebar("Statements")}}</div> </div> -<p><strong><code>do...while</code> 语句</strong><span lang="zh-CN"><span>创建一个执行指定语句的循环,直到</span></span><code>condition</code><span lang="zh-CN"><span>值为 false。</span><span>在执行</span></span><code>statement</code> <span lang="zh-CN"><span>后检测</span></span><code>condition</code><span lang="zh-CN"><span>,所以指定的</span></span><code>statement</code><span lang="zh-CN"><span>至少执行一次。</span></span></p> +<p><strong><code>do...while</code> 语句</strong>创建一个执行指定语句的循环,直到<code>condition</code>值为 false。在执行<code>statement</code> 后检测<code>condition</code>,所以指定的<code>statement</code>至少执行一次。</p> <h2 id="Syntax" name="Syntax">语法</h2> @@ -21,12 +21,12 @@ while (<em>condition</em>); <dl> <dt><code>statement</code></dt> - <dd><span class="short_text" id="result_box" lang="zh-CN"><span>执行至少一次的语句,并在每次 </span></span><code>condition</code> <span class="short_text" lang="zh-CN"><span>值为真时重新执行。</span></span>想执行多行语句,可使用<span style="line-height: 19.0909080505371px;">{{jsxref("Statements/block", "block")}}</span>语句<span style="line-height: 19.0909080505371px;">(</span><code style="font-style: normal; line-height: 19.0909080505371px;">{ ... }</code><span style="line-height: 19.0909080505371px;">)</span>包裹这些语句。</dd> + <dd>执行至少一次的语句,并在每次 <code>condition</code> 值为真时重新执行。想执行多行语句,可使用{{jsxref("Statements/block", "block")}}语句(<code style="font-style: normal; line-height: 19.0909080505371px;">{ ... }</code>)包裹这些语句。</dd> </dl> <dl> <dt><code>condition</code></dt> - <dd>循环中每次都会计算的表达式。如果 <code>condition</code> 值为真, <code>statement</code> 会再次执行。当 <code>condition</code> <span style="line-height: 19.0909080505371px;">值为假</span>,则跳到<code>do...while</code>之后的语句。</dd> + <dd>循环中每次都会计算的表达式。如果 <code>condition</code> 值为真, <code>statement</code> 会再次执行。当 <code>condition</code> 值为假,则跳到<code>do...while</code>之后的语句。</dd> </dl> <h2 id="Examples" name="Examples">示例</h2> @@ -37,17 +37,17 @@ while (<em>condition</em>); <h3 id="HTML_内容">HTML 内容</h3> -<pre class="brush: html line-numbers language-html"><code class="language-html"><span class="tag token"><span class="tag token"><span class="punctuation token"><</span>div</span> <span class="attr-name token">id</span><span class="attr-value token"><span class="punctuation token">=</span><span class="punctuation token">"</span>example<span class="punctuation token">"</span></span><span class="punctuation token">></span></span><span class="tag token"><span class="tag token"><span class="punctuation token"></</span>div</span><span class="punctuation token">></span></span></code></pre> +<pre class="brush: html line-numbers language-html"><code class="language-html"><div id="example"></div></code></pre> <h3 id="JavaScript_内容">JavaScript 内容</h3> -<pre class="brush: js"><code class="language-js"><span class="keyword token">var</span> result <span class="operator token">=</span> <span class="string token">''</span><span class="punctuation token">;</span> -<span class="keyword token">var</span> i <span class="operator token">=</span> <span class="number token">0</span><span class="punctuation token">;</span> -<span class="keyword token">do</span> <span class="punctuation token">{</span> - i <span class="operator token">+</span><span class="operator token">=</span> <span class="number token">1</span><span class="punctuation token">;</span> - result <span class="operator token">+</span><span class="operator token">=</span> i <span class="operator token">+</span> <span class="string token">' '</span><span class="punctuation token">;</span> -<span class="punctuation token">}</span> <span class="keyword token">while</span> <span class="punctuation token">(</span>i <span class="operator token"><</span> <span class="number token">5</span><span class="punctuation token">)</span><span class="punctuation token">;</span> -document<span class="punctuation token">.</span><span class="function token">getElementById</span><span class="punctuation token">(</span><span class="string token">'example'</span><span class="punctuation token">)</span><span class="punctuation token">.</span>innerHTML <span class="operator token">=</span> result<span class="punctuation token">;</span></code></pre> +<pre class="brush: js"><code class="language-js">var result = ''; +var i = 0; +do { + i += 1; + result += i + ' '; +} while (i < 5); +document.getElementById('example').innerHTML = result;</code></pre> <h3 id="结果">结果</h3> diff --git a/files/zh-cn/web/javascript/reference/statements/empty/index.html b/files/zh-cn/web/javascript/reference/statements/empty/index.html index 3a03a63165..d81f59a0dc 100644 --- a/files/zh-cn/web/javascript/reference/statements/empty/index.html +++ b/files/zh-cn/web/javascript/reference/statements/empty/index.html @@ -19,11 +19,11 @@ translation_of: Web/JavaScript/Reference/Statements/Empty <h2 id="描述">描述</h2> -<p><span class="short_text" id="result_box" lang="zh-CN"><span>空语句是一个分号(;),表示不会执行任何语句,即使 JavaScript 语法需要一个语句。</span></span> 相反,当你需要多行语句,但 JavaScript 只允许一个时,可以使用<a href="/zh-CN/docs/Web/JavaScript/Reference/Statements/block">语句块</a>;语句块可以将多条语句合并为一个。</p> +<p>空语句是一个分号(;),表示不会执行任何语句,即使 JavaScript 语法需要一个语句。 相反,当你需要多行语句,但 JavaScript 只允许一个时,可以使用<a href="/zh-CN/docs/Web/JavaScript/Reference/Statements/block">语句块</a>;语句块可以将多条语句合并为一个。</p> <h2 id="示例">示例</h2> -<p>空<span class="short_text" lang="zh-CN"><span>语句有时与循环语句一起使用。以下示例使用空循环体:</span></span></p> +<p>空语句有时与循环语句一起使用。以下示例使用空循环体:</p> <pre class="brush: js">var arr = [1, 2, 3]; diff --git a/files/zh-cn/web/javascript/reference/statements/export/index.html b/files/zh-cn/web/javascript/reference/statements/export/index.html index b97bb5c967..2eb0086a2f 100644 --- a/files/zh-cn/web/javascript/reference/statements/export/index.html +++ b/files/zh-cn/web/javascript/reference/statements/export/index.html @@ -11,7 +11,7 @@ translation_of: Web/JavaScript/Reference/Statements/export --- <div>{{jsSidebar("Statements")}}</div> -<p><span class="seoSummary">在创建JavaScript模块时,<code><strong>export</strong></code> 语句用于从模块中导出实时绑定的函数、对象或原始值,以便其他程序可以通过 {{jsxref("Statements/import", "import")}} 语句使用它们。被导出的绑定值依然可以在本地进行修改。在使用import进行导入时,这些绑定值只能被导入模块所读取,但在export导出模块中对这些绑定值进行修改,所修改的值也会实时地更新。</span></p> +<p>在创建JavaScript模块时,<code><strong>export</strong></code> 语句用于从模块中导出实时绑定的函数、对象或原始值,以便其他程序可以通过 {{jsxref("Statements/import", "import")}} 语句使用它们。被导出的绑定值依然可以在本地进行修改。在使用import进行导入时,这些绑定值只能被导入模块所读取,但在export导出模块中对这些绑定值进行修改,所修改的值也会实时地更新。</p> <p dir="ltr" id="tw-target-text">无论您是否声明,导出的模块都处于{{jsxref("Strict_mode","严格模式")}}。 export语句不能用在嵌入式脚本中。</p> diff --git a/files/zh-cn/web/javascript/reference/statements/for-await...of/index.html b/files/zh-cn/web/javascript/reference/statements/for-await...of/index.html index 47277b5f61..247677e1b9 100644 --- a/files/zh-cn/web/javascript/reference/statements/for-await...of/index.html +++ b/files/zh-cn/web/javascript/reference/statements/for-await...of/index.html @@ -16,7 +16,7 @@ translation_of: Web/JavaScript/Reference/Statements/for-await...of --- <p>{{jsSidebar("Statements")}}</p> -<p><strong><code>for await...of</code> 语句</strong>创建一个循环,该循环遍历异步可迭代对象以及同步可迭代对象,包括: <span style="">内置的 </span>{{jsxref("String")}}, {{jsxref("Array")}},<span style="">类似数组对象 (例如 </span>{{jsxref("Functions/arguments", "arguments")}} <span style="">或</span> {{DOMxRef("NodeList")}})<span style="">,</span>{{jsxref("TypedArray")}}, {{jsxref("Map")}}, {{jsxref("Set")}} <span style="">和用户定义的异步/同步迭代器。</span>它使用对象的每个不同属性的值调用要执行的语句来调用自定义迭代钩子。</p> +<p><strong><code>for await...of</code> 语句</strong>创建一个循环,该循环遍历异步可迭代对象以及同步可迭代对象,包括: 内置的 {{jsxref("String")}}, {{jsxref("Array")}},类似数组对象 (例如 {{jsxref("Functions/arguments", "arguments")}} 或 {{DOMxRef("NodeList")}}),{{jsxref("TypedArray")}}, {{jsxref("Map")}}, {{jsxref("Set")}} 和用户定义的异步/同步迭代器。它使用对象的每个不同属性的值调用要执行的语句来调用自定义迭代钩子。</p> <p>类似于 {{jsxref("Operators/await", "await")}} 运算符一样,该语句只能在一个{{jsxref("Statements/async_function", "async function", "异步函数", 1)}} 内部使用。</p> diff --git a/files/zh-cn/web/javascript/reference/statements/for...in/index.html b/files/zh-cn/web/javascript/reference/statements/for...in/index.html index 2e4318ba9f..7254cda762 100644 --- a/files/zh-cn/web/javascript/reference/statements/for...in/index.html +++ b/files/zh-cn/web/javascript/reference/statements/for...in/index.html @@ -133,9 +133,9 @@ for (var i = 0 in obj) { // 3 </pre> -<p><span style="line-height: 1.5;">这个非标准行为现在在版本40及更高版本中被忽略,并将在严格模式({{bug(748550)}} 和 </span>{{bug(1164741)}})<span style="line-height: 1.5;">中呈现{{jsxref("SyntaxError")}}("<a href="/zh-CN/docs/Web/JavaScript/Reference/Errors/Invalid_for-in_initializer">for-in loop head declarations may not have initializers</a>")错误。</span></p> +<p>这个非标准行为现在在版本40及更高版本中被忽略,并将在严格模式({{bug(748550)}} 和 {{bug(1164741)}})中呈现{{jsxref("SyntaxError")}}("<a href="/zh-CN/docs/Web/JavaScript/Reference/Errors/Invalid_for-in_initializer">for-in loop head declarations may not have initializers</a>")错误。</p> -<p><span style="line-height: 1.5;">像其他引擎 V8(Chrome),</span>Chakra (IE/Edge), JSC (WebKit/Safari) 正在研究去除这种不标准的行为。</p> +<p>像其他引擎 V8(Chrome),Chakra (IE/Edge), JSC (WebKit/Safari) 正在研究去除这种不标准的行为。</p> <h2 id="相关链接">相关链接</h2> diff --git a/files/zh-cn/web/javascript/reference/statements/for...of/index.html b/files/zh-cn/web/javascript/reference/statements/for...of/index.html index 2f05eafaaa..337714e022 100644 --- a/files/zh-cn/web/javascript/reference/statements/for...of/index.html +++ b/files/zh-cn/web/javascript/reference/statements/for...of/index.html @@ -152,7 +152,7 @@ for (let o of foo()) { <h3 id="迭代生成器">迭代生成器</h3> -<p><span><span>你还可以</span></span>迭代<span><span>一个</span></span><a href="/zh-CN/docs/Web/JavaScript/Reference/Statements/function*">生成器</a>:</p> +<p>你还可以迭代一个<a href="/zh-CN/docs/Web/JavaScript/Reference/Statements/function*">生成器</a>:</p> <pre class="brush:js">function* fibonacci() { // 一个生成器函数 let [prev, curr] = [0, 1]; diff --git a/files/zh-cn/web/javascript/reference/statements/function/index.html b/files/zh-cn/web/javascript/reference/statements/function/index.html index 98d1073a9d..dc052a53d0 100644 --- a/files/zh-cn/web/javascript/reference/statements/function/index.html +++ b/files/zh-cn/web/javascript/reference/statements/function/index.html @@ -19,7 +19,7 @@ translation_of: Web/JavaScript/Reference/Statements/function <div class="hidden">The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> and send us a pull request.</div> -<h2 id="语法"><span style="font-size: 2.14285714285714rem;">语法</span></h2> +<h2 id="语法">语法</h2> <pre class="eval notranslate">function <em>name</em>([<em>param</em>,[, <em>param</em>,[..., <em>param</em>]]]) { [<em>statements</em>] @@ -98,31 +98,23 @@ if (true) { <p>JavaScript 中的<strong>函数声明</strong>被提升到了<strong>函数定义</strong>。你可以在函数声明之前使用该函数:</p> -<pre class="brush: js language-js notranslate"><code class="language-js" style="direction: ltr; white-space: pre;"><span class="function token">hoisted<span class="punctuation token">(</span></span><span class="punctuation token">)</span><span class="punctuation token">;</span><span class="comment token"> // "foo" +<pre class="brush: js language-js notranslate"><code class="language-js" style="direction: ltr; white-space: pre;">hoisted(); // logs "foo" -</span><span class="keyword token">function</span> <span class="function token">hoisted<span class="punctuation token">(</span></span><span class="punctuation token">)</span> <span class="punctuation token">{</span> - console<span class="punctuation token">.</span><span class="function token">log<span class="punctuation token">(</span></span><span class="string token">"foo"</span><span class="punctuation token">)</span><span class="punctuation token">;</span> -<span class="punctuation token">} -</span> -<span class="comment token">/* equal to*/ -var </span><span class="function token">hoisted</span><span class="punctuation token">;</span><span class="comment token"> </span> - -<span class="function token">hoisted = </span><span class="keyword token">function</span><span class="function token"><span class="punctuation token">(</span></span><span class="punctuation token">)</span> <span class="punctuation token">{</span> - console<span class="punctuation token">.</span><span class="function token">log<span class="punctuation token">(</span></span><span class="string token">"foo"</span><span class="punctuation token">)</span><span class="punctuation token">;</span> -<span class="punctuation token">} -</span><span class="function token">hoisted<span class="punctuation token">(</span></span><span class="punctuation token">)</span><span class="punctuation token">;</span> -<span class="comment token">// "foo" </span></code> +function hoisted() { + console.log('foo'); +}</code> </pre> <div class="note"> <p>注意 :<strong>函数表达式</strong>{{jsxref("Operators/function", "function expressions")}} 不会被提升:</p> </div> -<pre class="brush: js language-js notranslate"><code class="language-js" style="direction: ltr; white-space: pre;"><span class="function token">notHoisted<span class="punctuation token">(</span></span><span class="punctuation token">)</span><span class="punctuation token">;</span><span class="comment token"> // TypeError: notHoisted is not a function -</span> -<span class="keyword token">var</span> notHoisted <span class="operator token">=</span> <span class="keyword token">function</span><span class="punctuation token">(</span><span class="punctuation token">)</span> <span class="punctuation token">{</span> - console<span class="punctuation token">.</span><span class="function token">log<span class="punctuation token">(</span></span><span class="string token">"bar"</span><span class="punctuation token">)</span><span class="punctuation token">;</span> -<span class="punctuation token">}</span><span class="punctuation token">;</span></code></pre> +<pre class="brush: js language-js notranslate"><code class="language-js" style="direction: ltr; white-space: pre;">notHoisted(); // TypeError: notHoisted is not a function + +var notHoisted = function() { + console.log('bar'); +}; +</code></pre> <h2 id="Examples" name="Examples">示例</h2> @@ -130,9 +122,9 @@ var </span><span class="function token">hoisted</span><span class="punctuation t <p>下面的代码声明了一个函数,该函数返回了销售的总金额, 参数是产品a,b,c分别的销售的数量.</p> -<pre class="brush: js language-js notranslate"><code class="language-js" style="direction: ltr; white-space: pre;"><span class="keyword token">function</span> <span class="function token">calc_sales<span class="punctuation token">(</span></span>units_a<span class="punctuation token">,</span> units_b<span class="punctuation token">,</span> units_c<span class="punctuation token">)</span> <span class="punctuation token">{</span> - <span class="keyword token">return</span> units_a<span class="operator token">*</span><span class="number token">79</span> <span class="operator token">+</span> units_b <span class="operator token">*</span> <span class="number token">129</span> <span class="operator token">+</span> units_c <span class="operator token">*</span> <span class="number token">699</span><span class="punctuation token">;</span> -<span class="punctuation token">}</span></code></pre> +<pre class="brush: js language-js notranslate"><code class="language-js" style="direction: ltr; white-space: pre;">function calc_sales(units_a, units_b, units_c) {functionfunctionfunctionfunctionfunctionfunctionfunctionfunctionfunctionfunctionfunction + return units_a*79 + units_b * 129 + units_c * 699; +}</code></pre> <h2 id="规范" style="margin-bottom: 20px; line-height: 30px; font-size: 2.14285714285714rem;">规范</h2> diff --git a/files/zh-cn/web/javascript/reference/statements/function_star_/index.html b/files/zh-cn/web/javascript/reference/statements/function_star_/index.html index 4e1f69883a..90794ec0d4 100644 --- a/files/zh-cn/web/javascript/reference/statements/function_star_/index.html +++ b/files/zh-cn/web/javascript/reference/statements/function_star_/index.html @@ -217,7 +217,7 @@ arr = [...gen]; // ["a", "b", "c", "d", "e"]</pre> <h4 id="IteratorResult不再抛出错误"><code>IteratorResult</code>不再抛出错误</h4> -<p>从Gecko 29 {{geckoRelease(29)}}开始,完成的生成器函数不再抛出{{jsxref("TypeError")}} "generator has already finished". 而是返回一个<code>IteratorResult</code>对象:<span style="font-family: consolas,monaco,andale mono,monospace;">{ value: undefined, done: true }</span> ({{bug(958951)}})。</p> +<p>从Gecko 29 {{geckoRelease(29)}}开始,完成的生成器函数不再抛出{{jsxref("TypeError")}} "generator has already finished". 而是返回一个<code>IteratorResult</code>对象:{ value: undefined, done: true } ({{bug(958951)}})。</p> <h2 id="相关链接">相关链接</h2> diff --git a/files/zh-cn/web/javascript/reference/statements/if...else/index.html b/files/zh-cn/web/javascript/reference/statements/if...else/index.html index 991e36f52d..ea26ed78af 100644 --- a/files/zh-cn/web/javascript/reference/statements/if...else/index.html +++ b/files/zh-cn/web/javascript/reference/statements/if...else/index.html @@ -10,7 +10,7 @@ translation_of: Web/JavaScript/Reference/Statements/if...else <div> {{jsSidebar("Statements")}}</div> </div> -<p><span style="line-height: 19.0909080505371px;">当指定条件为真,</span><strong>if 语句</strong>会执行一段语句。如果条件为假,则执行另一段语句。</p> +<p>当指定条件为真,<strong>if 语句</strong>会执行一段语句。如果条件为假,则执行另一段语句。</p> <p>{{EmbedInteractiveExample("pages/js/statement-ifelse.html")}}</p> @@ -38,7 +38,7 @@ translation_of: Web/JavaScript/Reference/Statements/if...else <dl> <dt><code>statement2</code></dt> - <dd>如果<code>condition</code>为假且 <code>else</code>从句存在时执行的语句。<span style="line-height: 19.0909080505371px;">可为任意语句,包括块语句和</span>嵌套的<code>if</code>语句<span style="line-height: 19.0909080505371px;">。</span></dd> + <dd>如果<code>condition</code>为假且 <code>else</code>从句存在时执行的语句。可为任意语句,包括块语句和嵌套的<code>if</code>语句。</dd> </dl> <h2 id="Description" name="Description">说明</h2> diff --git a/files/zh-cn/web/javascript/reference/statements/import/index.html b/files/zh-cn/web/javascript/reference/statements/import/index.html index 203ce9b8cc..0c7f0a0a4f 100644 --- a/files/zh-cn/web/javascript/reference/statements/import/index.html +++ b/files/zh-cn/web/javascript/reference/statements/import/index.html @@ -99,7 +99,7 @@ var promise = import("module-name");//这是一个处于第三阶段的提案。 <h3 id="导入默认值">导入默认值</h3> -<p><code><font face="Arial, x-locale-body, sans-serif"><span style="background-color: #ffffff;">引入模块可能有一个</span></font>default</code>{{jsxref("Statements/export", "export")}}(无论它是对象,函数,类等)可用。然后可以使用<code>import</code>语句来导入这样的默认接口。</p> +<p><code><font face="Arial, x-locale-body, sans-serif">引入模块可能有一个</font>default</code>{{jsxref("Statements/export", "export")}}(无论它是对象,函数,类等)可用。然后可以使用<code>import</code>语句来导入这样的默认接口。</p> <p>最简单的用法是直接导入默认值:</p> diff --git a/files/zh-cn/web/javascript/reference/statements/index.html b/files/zh-cn/web/javascript/reference/statements/index.html index c6d70fce55..570cb1adff 100644 --- a/files/zh-cn/web/javascript/reference/statements/index.html +++ b/files/zh-cn/web/javascript/reference/statements/index.html @@ -16,7 +16,7 @@ translation_of: Web/JavaScript/Reference/Statements <p>若需要按字母顺序排列的列表,请参阅左侧边栏。</p> -<h3 id="控制流程"><span class="short_text" id="result_box" lang="zh-CN"><span>控制流程</span></span></h3> +<h3 id="控制流程">控制流程</h3> <dl> <dt>{{jsxref("Statements/block", "Block")}}</dt> diff --git a/files/zh-cn/web/javascript/reference/statements/try...catch/index.html b/files/zh-cn/web/javascript/reference/statements/try...catch/index.html index abfcac785b..587da47b18 100644 --- a/files/zh-cn/web/javascript/reference/statements/try...catch/index.html +++ b/files/zh-cn/web/javascript/reference/statements/try...catch/index.html @@ -113,7 +113,7 @@ catch (e) { } </pre> -<p>下面用符合 ECMAscript 规范的简单的 JavaScript 来编写相同的“条件catch子句”(显然更加<span class="s1">冗长的</span>,但是可以在任何地方运行):</p> +<p>下面用符合 ECMAscript 规范的简单的 JavaScript 来编写相同的“条件catch子句”(显然更加冗长的,但是可以在任何地方运行):</p> <pre class="brush: js">try { myRoutine(); |