aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/statements
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/javascript/reference/statements')
-rw-r--r--files/zh-cn/web/javascript/reference/statements/async_function/index.html17
-rw-r--r--files/zh-cn/web/javascript/reference/statements/break/index.html4
-rw-r--r--files/zh-cn/web/javascript/reference/statements/class/index.html1
-rw-r--r--files/zh-cn/web/javascript/reference/statements/continue/index.html6
-rw-r--r--files/zh-cn/web/javascript/reference/statements/debugger/index.html4
-rw-r--r--files/zh-cn/web/javascript/reference/statements/do...while/index.html2
-rw-r--r--files/zh-cn/web/javascript/reference/statements/export/index.html4
-rw-r--r--files/zh-cn/web/javascript/reference/statements/for-await...of/index.html4
-rw-r--r--files/zh-cn/web/javascript/reference/statements/for...in/index.html2
-rw-r--r--files/zh-cn/web/javascript/reference/statements/for/index.html2
-rw-r--r--files/zh-cn/web/javascript/reference/statements/function/index.html8
-rw-r--r--files/zh-cn/web/javascript/reference/statements/import/index.html2
-rw-r--r--files/zh-cn/web/javascript/reference/statements/return/index.html2
-rw-r--r--files/zh-cn/web/javascript/reference/statements/with/index.html6
14 files changed, 34 insertions, 30 deletions
diff --git a/files/zh-cn/web/javascript/reference/statements/async_function/index.html b/files/zh-cn/web/javascript/reference/statements/async_function/index.html
index ba79f6a5d2..5088f77130 100644
--- a/files/zh-cn/web/javascript/reference/statements/async_function/index.html
+++ b/files/zh-cn/web/javascript/reference/statements/async_function/index.html
@@ -35,22 +35,21 @@ translation_of: Web/JavaScript/Reference/Statements/async_function
<dd>要传递给函数的参数的名称。</dd>
<dt><code>statements</code></dt>
<dd>包含函数主体的表达式。可以使用<code>await</code>机制。</dd>
- <dt>
- <h3 id="返回值">返回值</h3>
- </dt>
- <dd>一个{{jsxref("Promise")}},这个promise要么会通过一个由async函数返回的值被解决,要么会通过一个从async函数中抛出的(或其中没有被捕获到的)异常被拒绝。</dd>
</dl>
+<h3 id="返回值">返回值</h3>
+<p>一个{{jsxref("Promise")}},这个promise要么会通过一个由async函数返回的值被解决,要么会通过一个从async函数中抛出的(或其中没有被捕获到的)异常被拒绝。</p>
+
<h2 id="描述">描述</h2>
<p>async函数可能包含0个或者多个{{jsxref("Operators/await", "await")}}表达式。await表达式会暂停整个async函数的执行进程并出让其控制权,只有当其等待的基于promise的异步操作被兑现或被拒绝之后才会恢复进程。promise的解决值会被当作该await表达式的返回值。使用<code>async</code> / <code>await</code>关键字就可以在异步代码中使用普通的<code>try</code> / <code>catch</code>代码块。</p>
<div class="note">
-<p><code>await</code>关键字只在async函数内有效。如果你在async函数体之外使用它,就会抛出语法错误 {{jsxref("SyntaxError")}} 。</p>
+<p><strong>备注:</strong><code>await</code>关键字只在async函数内有效。如果你在async函数体之外使用它,就会抛出语法错误 {{jsxref("SyntaxError")}} 。</p>
</div>
<div class="note">
-<p><code>async</code>/<code>await</code>的目的为了简化使用基于promise的API时所需的语法。<code>async</code>/<code>await</code>的行为就好像搭配使用了生成器和promise。</p>
+<p><strong>备注:</strong><code>async</code>/<code>await</code>的目的为了简化使用基于promise的API时所需的语法。<code>async</code>/<code>await</code>的行为就好像搭配使用了生成器和promise。</p>
</div>
<p>async函数一定会返回一个promise对象。如果一个async函数的返回值看起来不是promise,那么它将会被隐式地包装在一个promise中。</p>
@@ -200,6 +199,7 @@ setTimeout(parallelPromise, 13000); // same as parallel
</pre>
<div class="note">
+<p><strong>备注:</strong></p>
<h4 id="await_and_parallelism并行"><code>await</code> and parallelism(并行)</h4>
<p>在<code>sequentialStart</code>中,程序在第一个<code>await</code>停留了2秒,然后又在第二个<code>await</code>停留了1秒。直到第一个计时器结束后,第二个计时器才被创建。程序需要3秒执行完毕。</p>
@@ -213,6 +213,7 @@ setTimeout(parallelPromise, 13000); // same as parallel
</div>
<div class="warning">
+<p><strong>警告:</strong></p>
<h4 id="asyncawait和Promisethen对比以及错误处理"><code>async</code>/<code>await和</code>Promise#then对比以及错误处理</h4>
<p>大多数async函数也可以使用Promises编写。但是,在错误处理方面,async函数更容易捕获异常错误</p>
@@ -255,8 +256,8 @@ setTimeout(parallelPromise, 13000); // same as parallel
<p>注意,在上述示例中,<code>return</code> 语句中没有 <code>await</code> 操作符,因为 <code>async function</code> 的返回值将被隐式地传递给 <code>{{jsxref("Promise.resolve")}}</code>。</p>
-<div class="blockIndicator note">
-<p><strong><code>return await promiseValue;</code> 与 <code>return promiseValue;的比较</code></strong></p>
+<div class="note">
+<p><strong>备注:</strong></p>
<p>返回值<code>隐式的传递给</code>{{jsxref("Promise.resolve")}},并不意味着<code>return await promiseValue;和return promiseValue;</code>在功能上相同。</p>
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 cce30700ab..0f61d23f95 100644
--- a/files/zh-cn/web/javascript/reference/statements/break/index.html
+++ b/files/zh-cn/web/javascript/reference/statements/break/index.html
@@ -68,7 +68,7 @@ switch (food) {
<p>下面的代码中一起使用 <code>break</code> 语句和被标记的块语句。一个 <code>break</code> 语句必须内嵌在它引用的标记中。注意,<code>inner_block</code> 内嵌在 <code>outer_block</code> 中。</p>
-<pre class="brush:js;highlight:[1,3,5];">outer_block:{
+<pre class="brush:js;">outer_block:{
inner_block:{
console.log ('1');
@@ -84,7 +84,7 @@ switch (food) {
<p>下面的代码同样使用了 <code>break</code> 语句和被标记的块语句,但是产生了一个语法错误,因为它的 <code>break</code> 语句在 <code>block_1</code> 中,但是引用了 <code>block_2</code>。<code>break</code> 语句必须内嵌在它引用的标签中。</p>
-<pre class="brush:js;highlight:[1,3,6];">block_1:{
+<pre class="brush:js;">block_1:{
console.log ('1');
break block_2; // SyntaxError: label not found
}
diff --git a/files/zh-cn/web/javascript/reference/statements/class/index.html b/files/zh-cn/web/javascript/reference/statements/class/index.html
index b4b8afdbd6..f90b560270 100644
--- a/files/zh-cn/web/javascript/reference/statements/class/index.html
+++ b/files/zh-cn/web/javascript/reference/statements/class/index.html
@@ -57,6 +57,7 @@ class Square extends Polygon {
}</pre>
<div class="warning">
+<p><strong>警告:</strong></p>
<h3 id="重复定义类">重复定义类</h3>
<p>重复声明一个类会引起类型错误。</p>
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 9d8954fb84..d356fdde7f 100644
--- a/files/zh-cn/web/javascript/reference/statements/continue/index.html
+++ b/files/zh-cn/web/javascript/reference/statements/continue/index.html
@@ -40,7 +40,7 @@ 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">i = 0;
+<pre class="brush: js">i = 0;
n = 0;
while (i &lt; 5) {
i++;
@@ -58,7 +58,7 @@ while (i &lt; 5) {
<p>参考 {{jsxref("Statements/label", "label")}} 。</p>
-<pre class="brush: js language-js">var i = 0,
+<pre class="brush: js">var i = 0,
j = 8;
checkiandj: while (i &lt; 4) {
@@ -78,7 +78,7 @@ checkiandj: while (i &lt; 4) {
<p>输出:</p>
-<pre class="brush: js language-js">"i: 0"
+<pre class="brush: js">"i: 0"
// start checkj
"j: 8"
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 d87e77bfb8..dc8ca25936 100644
--- a/files/zh-cn/web/javascript/reference/statements/debugger/index.html
+++ b/files/zh-cn/web/javascript/reference/statements/debugger/index.html
@@ -19,14 +19,14 @@ translation_of: Web/JavaScript/Reference/Statements/debugger
<p>下面的例子演示了一个包含 debugger 语句的函数,当函数被调用时,会尝试调用一个可用的调试器进行调试。</p>
-<pre class="brush:js language-js">function potentiallyBuggyCode() {
+<pre class="brush:js">function potentiallyBuggyCode() {
debugger;
// do potentially buggy stuff to examine, step through, etc.
}</pre>
<p>当 debugger 被调用时, 执行暂停在 debugger 语句的位置。就像在脚本源代码中的断点一样。</p>
-<p><a href="https://mdn.mozillademos.org/files/6963/Screen%20Shot%202014-02-07%20at%209.14.35%20AM.png"><img alt="Paused at a debugger statement." src="https://mdn.mozillademos.org/files/6963/Screen%20Shot%202014-02-07%20at%209.14.35%20AM.png" style="height: 371px; width: 700px;"></a></p>
+<p><a href="https://mdn.mozillademos.org/files/6963/Screen%20Shot%202014-02-07%20at%209.14.35%20AM.png"><img alt="Paused at a debugger statement." src="https://mdn.mozillademos.org/files/6963/Screen%20Shot%202014-02-07%20at%209.14.35%20AM.png"></a></p>
<h2 id="规范">规范</h2>
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 9f013042b9..dffd5e085b 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
@@ -34,7 +34,7 @@ while (<em>condition</em>);
<h3 id="HTML_内容">HTML 内容</h3>
-<pre class="brush: html line-numbers language-html">&lt;div id="example"&gt;&lt;/div&gt;</pre>
+<pre class="brush: html">&lt;div id="example"&gt;&lt;/div&gt;</pre>
<h3 id="JavaScript_内容">JavaScript 内容</h3>
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 bcffc5aafc..8d1e1d3b3a 100644
--- a/files/zh-cn/web/javascript/reference/statements/export/index.html
+++ b/files/zh-cn/web/javascript/reference/statements/export/index.html
@@ -117,8 +117,8 @@ export { function1, function2 };
<p>但这里的 <code>function1</code> 和 <code>function2</code> 在当前模块中变得不可用。</p>
-<div class="blockIndicator note">
-<p>注意:尽管与import等效,但以下语法在语法上无效:</p>
+<div class="note">
+<p><strong>备注:</strong>尽管与import等效,但以下语法在语法上无效:</p>
</div>
<pre class="brush: js">import DefaultExport from 'bar.js'; // 有效的
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 597426a1fc..272bc49fb1 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
@@ -20,8 +20,8 @@ translation_of: Web/JavaScript/Reference/Statements/for-await...of
<p>类似于 {{jsxref("Operators/await", "await")}} 运算符一样,该语句只能在一个{{jsxref("Statements/async_function", "async function", "异步函数", 1)}} 内部使用。</p>
-<div class="blockIndicator note">
-<p><code>for await...of</code> 不适用于不是异步可迭代的异步迭代器。</p>
+<div class="note">
+<p><strong>备注:</strong><code>for await...of</code> 不适用于不是异步可迭代的异步迭代器。</p>
</div>
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 964a6d7a8d..ed54183732 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
@@ -27,7 +27,7 @@ translation_of: Web/JavaScript/Reference/Statements/for...in
<h3 id="数组迭代和_for...in">数组迭代和 <code>for...in</code></h3>
<div class="note">
-<p><strong>提示:</strong><code>for...in</code>不应该用于迭代一个关注索引顺序的 {{jsxref("Array")}}。</p>
+<p><strong>备注:</strong><code>for...in</code>不应该用于迭代一个关注索引顺序的 {{jsxref("Array")}}。</p>
</div>
<h3 id="仅迭代自身的属性">仅迭代自身的属性</h3>
diff --git a/files/zh-cn/web/javascript/reference/statements/for/index.html b/files/zh-cn/web/javascript/reference/statements/for/index.html
index 0a904c3473..9e8eb05f51 100644
--- a/files/zh-cn/web/javascript/reference/statements/for/index.html
+++ b/files/zh-cn/web/javascript/reference/statements/for/index.html
@@ -110,7 +110,7 @@ showOffsetPos('content');
// top: 153px;"</pre>
<div class="note">
-<p><strong>提示:</strong><strong>这里的分号是强制性的</strong>,是 JavaScript 中的少数几种强制分号的情况。如果没有分号,循环声明之后的行将被视为循环语句。</p>
+<p><strong>备注:</strong><strong>这里的分号是强制性的</strong>,是 JavaScript 中的少数几种强制分号的情况。如果没有分号,循环声明之后的行将被视为循环语句。</p>
</div>
<h2 id="规范">规范</h2>
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 cb225706eb..13efc35a6d 100644
--- a/files/zh-cn/web/javascript/reference/statements/function/index.html
+++ b/files/zh-cn/web/javascript/reference/statements/function/index.html
@@ -90,7 +90,7 @@ if (true) {
<p>JavaScript 中的<strong>函数声明</strong>被提升到了<strong>函数定义</strong>。你可以在函数声明之前使用该函数:</p>
-<pre class="brush: js language-js">hoisted(); // logs "foo"
+<pre class="brush: js">hoisted(); // logs "foo"
function hoisted() {
console.log('foo');
@@ -98,10 +98,10 @@ function hoisted() {
</pre>
<div class="note">
-<p>注意 :<strong>函数表达式</strong>{{jsxref("Operators/function", "function expressions")}} 不会被提升:</p>
+<p><strong>备注:</strong><strong>函数表达式</strong>{{jsxref("Operators/function", "function expressions")}} 不会被提升:</p>
</div>
-<pre class="brush: js language-js">notHoisted(); // TypeError: notHoisted is not a function
+<pre class="brush: js">notHoisted(); // TypeError: notHoisted is not a function
var notHoisted = function() {
console.log('bar');
@@ -114,7 +114,7 @@ var notHoisted = function() {
<p>下面的代码声明了一个函数,该函数返回了销售的总金额, 参数是产品a,b,c分别的销售的数量.</p>
-<pre class="brush: js language-js">function calc_sales(units_a, units_b, units_c) {functionfunctionfunctionfunctionfunctionfunctionfunctionfunctionfunctionfunctionfunction
+<pre class="brush: js">function calc_sales(units_a, units_b, units_c) {functionfunctionfunctionfunctionfunctionfunctionfunctionfunctionfunctionfunctionfunction
return units_a*79 + units_b * 129 + units_c * 699;
}</pre>
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 8daa4187e2..4b59374f0a 100644
--- a/files/zh-cn/web/javascript/reference/statements/import/index.html
+++ b/files/zh-cn/web/javascript/reference/statements/import/index.html
@@ -21,7 +21,7 @@ translation_of: Web/JavaScript/Reference/Statements/import
<p>语法</p>
-<pre class="syntaxbox brush: js">import <em>defaultExport</em> from "<em>module-name</em>";
+<pre class="brush: js">import <em>defaultExport</em> from "<em>module-name</em>";
import * as <em>name</em> from "<em>module-name</em>";
import { <em>export </em>} from "<em>module-name</em>";
import { <em>export</em> as <em>alias </em>} from "<em>module-name</em>";
diff --git a/files/zh-cn/web/javascript/reference/statements/return/index.html b/files/zh-cn/web/javascript/reference/statements/return/index.html
index 473f330f50..e5a09d5a84 100644
--- a/files/zh-cn/web/javascript/reference/statements/return/index.html
+++ b/files/zh-cn/web/javascript/reference/statements/return/index.html
@@ -57,7 +57,7 @@ a + b;</pre>
<p>控制台会警告“unreachable code after return statement”。</p>
<div class="note">
-<p>从 Gecko 40 {{geckoRelease(40)}}开始,如果在一个 return 语句后发现无法访问的代码,控制台将会显示一个警告。</p>
+<p><strong>备注:</strong>从 Gecko 40 {{geckoRelease(40)}}开始,如果在一个 return 语句后发现无法访问的代码,控制台将会显示一个警告。</p>
</div>
<h2 id="Examples">示例</h2>
diff --git a/files/zh-cn/web/javascript/reference/statements/with/index.html b/files/zh-cn/web/javascript/reference/statements/with/index.html
index cca0407da3..93d4270d2e 100644
--- a/files/zh-cn/web/javascript/reference/statements/with/index.html
+++ b/files/zh-cn/web/javascript/reference/statements/with/index.html
@@ -7,7 +7,9 @@ tags:
- Statement
translation_of: Web/JavaScript/Reference/Statements/with
---
-<div class="warning">不建议使用<code>with</code>语句,因为它可能是混淆错误和兼容性问题的根源。有关详细信息,请参阅下面“描述”一节中的“语意不明的弊端”部分。</div>
+<div class="warning">
+<p><strong>警告:</strong>不建议使用<code>with</code>语句,因为它可能是混淆错误和兼容性问题的根源。有关详细信息,请参阅下面“描述”一节中的“语意不明的弊端”部分。</p>
+</div>
<div>{{jsSidebar("Statements")}}</div>
@@ -31,7 +33,7 @@ translation_of: Web/JavaScript/Reference/Statements/with
<p>JavaScript查找某个未使用命名空间的变量时,会通过作用域链来查找,作用域链是跟执行代码的context或者包含这个变量的函数有关。'with'语句将某个对象添加到作用域链的顶部,如果在statement中有某个未使用命名空间的变量,跟作用域链中的某个属性同名,则这个变量将指向这个属性值。如果沒有同名的属性,则将拋出{{jsxref("ReferenceError")}}异常。</p>
-<div class="note">不推荐使用<code>with</code>,在 ECMAScript 5 <a href="/zh-CN/docs/Web/JavaScript/Reference/Strict_mode">严格模式</a>中该标签已被禁止。推荐的替代方案是声明一个临时变量来承载你所需要的属性。</div>
+<div class="note"><p><strong>备注:</strong>不推荐使用<code>with</code>,在 ECMAScript 5 <a href="/zh-CN/docs/Web/JavaScript/Reference/Strict_mode">严格模式</a>中该标签已被禁止。推荐的替代方案是声明一个临时变量来承载你所需要的属性。</p></div>
<h3 id="性能方面的利与弊">性能方面的利与弊</h3>