aboutsummaryrefslogtreecommitdiff
path: root/files/zh-tw/web/javascript/reference/statements
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-tw/web/javascript/reference/statements')
-rw-r--r--files/zh-tw/web/javascript/reference/statements/async_function/index.html8
-rw-r--r--files/zh-tw/web/javascript/reference/statements/block/index.html4
-rw-r--r--files/zh-tw/web/javascript/reference/statements/break/index.html8
-rw-r--r--files/zh-tw/web/javascript/reference/statements/debugger/index.html2
-rw-r--r--files/zh-tw/web/javascript/reference/statements/for...in/index.html8
-rw-r--r--files/zh-tw/web/javascript/reference/statements/label/index.html4
-rw-r--r--files/zh-tw/web/javascript/reference/statements/let/index.html6
-rw-r--r--files/zh-tw/web/javascript/reference/statements/return/index.html2
-rw-r--r--files/zh-tw/web/javascript/reference/statements/throw/index.html80
-rw-r--r--files/zh-tw/web/javascript/reference/statements/var/index.html80
10 files changed, 25 insertions, 177 deletions
diff --git a/files/zh-tw/web/javascript/reference/statements/async_function/index.html b/files/zh-tw/web/javascript/reference/statements/async_function/index.html
index 1111e54da6..7faf5dcfef 100644
--- a/files/zh-tw/web/javascript/reference/statements/async_function/index.html
+++ b/files/zh-tw/web/javascript/reference/statements/async_function/index.html
@@ -45,8 +45,8 @@ translation_of: Web/JavaScript/Reference/Statements/async_function
<p>async 函式內部可以使用 {{jsxref("Operators/await", "await")}} 表達式,它會暫停此 async 函式的執行,並且等待傳遞至表達式的 Promise 的解析,解析完之後會回傳解析值,並繼續此 async 函式的執行。</p>
-<div class="note">
-<p><code>async/await</code> 函式的目的在於簡化同步操作 promise 的表現,以及對多個 <code>Promise</code> 物件執行某些操作。就像 <code>Promise 類似於具結構性的回呼函式,同樣地,async/await 好比將 generator 與 promise 組合起來。</code></p>
+<div class="notecard note">
+<p><strong>備註:</strong><code>async/await</code> 函式的目的在於簡化同步操作 promise 的表現,以及對多個 <code>Promise</code> 物件執行某些操作。就像 <code>Promise 類似於具結構性的回呼函式,同樣地,async/await 好比將 generator 與 promise 組合起來。</code></p>
</div>
<h2 id="範例">範例</h2>
@@ -84,8 +84,8 @@ add2(10).then(v =&gt; {
});
</pre>
-<div class="warning">
-<h4 id="不要誤解_Promise.all_的_await">不要誤解 <code>Promise.all</code> 的 <code>await</code></h4>
+<div class="notecard warning">
+<p><strong>警告:</strong>不要誤解 <code>Promise.all</code> 的 <code>await</code></p>
<p>在 <code>add1</code> 裡,該執行為了第一個 <code>await</code> 而暫停了兩秒,接著為了第二個 <code>await</code> 又暫停了兩秒。在第一個計時器(timer)被觸發前,第二個計時器並不會被建立。而在 <code>add2</code> 裡,兩個計時器都被建立起來、也都執行 <code>await</code> 過了。這把它帶往了 resolve 所的 2 秒暫停、而不是 4 秒暫停。然而這兩個 <code>await</code> 呼叫都在連續運行,而非平行運行。<code>await</code> <strong>並不是</strong> <code>Promise.all</code> 的自動程式。如果你想讓兩個、甚至兩個以上的 <code>await</code> promises 同時執行(in parallel),你必須使用 <code>Promise.all</code>.</p>
</div>
diff --git a/files/zh-tw/web/javascript/reference/statements/block/index.html b/files/zh-tw/web/javascript/reference/statements/block/index.html
index 0e1d2ce662..a62ff2583e 100644
--- a/files/zh-tw/web/javascript/reference/statements/block/index.html
+++ b/files/zh-tw/web/javascript/reference/statements/block/index.html
@@ -12,7 +12,7 @@ translation_of: Web/JavaScript/Reference/Statements/block
<table class="standard-table">
<tbody>
<tr>
- <td class="header" colspan="2">陳述句</td>
+ <th colspan="2">陳述句</th>
</tr>
<tr>
<td>Implemented in</td>
@@ -63,7 +63,7 @@ alert(x); // outputs 2
<p>當使用<code>let</code>或是<code>const</code>進行宣告時,其存取範圍是只有本身定義的區塊中。</p>
-<pre class="brush: js line-numbers language-js">let x = 1;
+<pre class="brush: js">let x = 1;
{
let x = 2;
}
diff --git a/files/zh-tw/web/javascript/reference/statements/break/index.html b/files/zh-tw/web/javascript/reference/statements/break/index.html
index ff72f9d25b..b5fa73113e 100644
--- a/files/zh-tw/web/javascript/reference/statements/break/index.html
+++ b/files/zh-tw/web/javascript/reference/statements/break/index.html
@@ -25,13 +25,13 @@ translation_of: Web/JavaScript/Reference/Statements/break
<h2 id="說明">說明</h2>
-<p>中斷陳述 <code>break</code> 可加上標籤 (label) 參數,使其跳出被標籤的陳述語句。此中斷陳述 <code>break</code> 必須被包含在被標籤的陳述語句中。被標籤的陳述語句可被添加於任一個區塊 (<a class="internal" href="/en-US/docs/JavaScript/Reference/Statements/block" title="JavaScript/Reference/Statements/Block">block</a>) 前,而非限定在迴圈陳述。</p>
+<p>中斷陳述 <code>break</code> 可加上標籤 (label) 參數,使其跳出被標籤的陳述語句。此中斷陳述 <code>break</code> 必須被包含在被標籤的陳述語句中。被標籤的陳述語句可被添加於任一個區塊 (<a href="/en-US/docs/JavaScript/Reference/Statements/block" title="JavaScript/Reference/Statements/Block">block</a>) 前,而非限定在迴圈陳述。</p>
<h2 id="範例">範例</h2>
<p>下面函式包含一個中斷陳述 <code>break</code> ,當 <code>i</code> 值為 3 時,中斷 <code>while</code> 迴圈,並回傳 <code>3 * x</code> 。</p>
-<pre class="brush:js;highlight:[6];">function testBreak(x) {
+<pre class="brush:js">function testBreak(x) {
var i = 0;
while (i &lt; 6) {
@@ -46,7 +46,7 @@ translation_of: Web/JavaScript/Reference/Statements/break
<p>The following code uses <code>break</code> statements with labeled blocks. A <code>break</code> statement must be nested within any label it references. Notice that <code>inner_block</code> is nested within <code>outer_block</code>.</p>
-<pre class="brush:js;highlight:[1,2,4];">outer_block: {
+<pre class="brush:js">outer_block: {
inner_block: {
console.log('1');
break outer_block; // breaks out of both inner_block and outer_block
@@ -58,7 +58,7 @@ translation_of: Web/JavaScript/Reference/Statements/break
<p>The following code also uses <code>break</code> statements with labeled blocks but generates a Syntax Error because its <code>break</code> statement is within <code>block_1</code> but references <code>block_2</code>. A <code>break</code> statement must always be nested within any label it references.</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-tw/web/javascript/reference/statements/debugger/index.html b/files/zh-tw/web/javascript/reference/statements/debugger/index.html
index 79a65a398e..d5d1662cf4 100644
--- a/files/zh-tw/web/javascript/reference/statements/debugger/index.html
+++ b/files/zh-tw/web/javascript/reference/statements/debugger/index.html
@@ -22,7 +22,7 @@ translation_of: Web/JavaScript/Reference/Statements/debugger
<p>呼叫除錯器時,程式會在 debugger 宣告處暫停執行。它有點像是程式碼的斷點。</p>
-<p><a href="https://mdn.mozillademos.org/files/6963/Screen Shot 2014-02-07 at 9.14.35 AM.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 Shot 2014-02-07 at 9.14.35 AM.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-tw/web/javascript/reference/statements/for...in/index.html b/files/zh-tw/web/javascript/reference/statements/for...in/index.html
index 92ab3aa5c0..727397cce0 100644
--- a/files/zh-tw/web/javascript/reference/statements/for...in/index.html
+++ b/files/zh-tw/web/javascript/reference/statements/for...in/index.html
@@ -47,12 +47,12 @@ translation_of: Web/JavaScript/Reference/Statements/for...in
<p>A <code>for...in</code> loop iterates over the properties of an object in an arbitrary order (see the <a href="/en-US/docs/JavaScript/Reference/Operators/delete#Cross-browser_issues">delete operator</a> for more on why one cannot depend on the seeming orderliness of iteration, at least in a cross-browser setting). If a property is modified in one iteration and then visited at a later time, its value in the loop is its value at that later time. A property that is deleted before it has been visited will not be visited later. Properties added to the object over which iteration is occurring may either be visited or omitted from iteration. In general it is best not to add, modify or remove properties from the object during iteration, other than the property currently being visited. There is no guarantee whether or not an added property will be visited, whether a modified property (other than the current one) will be visited before or after it is modified, or whether a deleted property will be visited before it is deleted.</p>
-<div class="note">
-<p>If you only want to consider properties attached to the object itself, and not its prototypes, use <a href="/en-US/docs/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames">getOwnPropertyNames</a> or perform a <a href="/en-US/docs/JavaScript/Reference/Global_Objects/Object/hasOwnProperty">hasOwnProperty</a> check (<a href="/en-US/docs/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable">propertyIsEnumerable</a> can also be used). Alternatively, if you know there won't be any outside code interference, you can extend built-in prototypes with a check method.</p>
+<div class="notecard note">
+<p><strong>Note:</strong> If you only want to consider properties attached to the object itself, and not its prototypes, use <a href="/en-US/docs/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames">getOwnPropertyNames</a> or perform a <a href="/en-US/docs/JavaScript/Reference/Global_Objects/Object/hasOwnProperty">hasOwnProperty</a> check (<a href="/en-US/docs/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable">propertyIsEnumerable</a> can also be used). Alternatively, if you know there won't be any outside code interference, you can extend built-in prototypes with a check method.</p>
</div>
-<div class="note">
-<p><strong><code>for..in</code> 不應該用來迭代一個索引順序很重要的<a href="/en-US/docs/JavaScript/Reference/Global_Objects/Array">陣列</a>。</strong> 陣列索引只是以整數命名的可列舉屬性,其他方面等同於一般物件屬性。 無法擔保 <code>for...in</code> 以特定順序傳回索引,並且它將傳回全部可列舉屬性,包括非整數名的,以及繼承而來的可列舉屬性。</p>
+<div class="notecard note">
+<p><strong>備註:</strong><strong><code>for..in</code> 不應該用來迭代一個索引順序很重要的<a href="/en-US/docs/JavaScript/Reference/Global_Objects/Array">陣列</a>。</strong> 陣列索引只是以整數命名的可列舉屬性,其他方面等同於一般物件屬性。 無法擔保 <code>for...in</code> 以特定順序傳回索引,並且它將傳回全部可列舉屬性,包括非整數名的,以及繼承而來的可列舉屬性。</p>
<p>因為迭代的順序依賴於 JavaScript 引擎的實作,在不同引擎下,迭代一個陣列可能不是以一個一致的順序存取陣列元素。因此,當你迭代陣列,且該陣列的存取順序很重要時,最好是使用以數值索引的 <a href="/en-US/docs/JavaScript/Reference/Statements/for">for</a> 迴圈 (或 <a href="/en-US/docs/JavaScript/Reference/Global_Objects/Array/forEach">Array.forEach</a> 或非標準 <code><a href="/en-US/docs/JavaScript/Reference/Statements/for...of">for...of</a></code> 迴圈)。</p>
</div>
diff --git a/files/zh-tw/web/javascript/reference/statements/label/index.html b/files/zh-tw/web/javascript/reference/statements/label/index.html
index b8ba54d920..b67148b359 100644
--- a/files/zh-tw/web/javascript/reference/statements/label/index.html
+++ b/files/zh-tw/web/javascript/reference/statements/label/index.html
@@ -15,8 +15,8 @@ translation_of: Web/JavaScript/Reference/Statements/label
-<div class="note">
-<p>標記的迴圈或程式碼區塊非常罕見。通常可以使用函式呼叫而不是使用迴圈跳轉。</p>
+<div class="notecard note">
+<p><strong>備註:</strong>標記的迴圈或程式碼區塊非常罕見。通常可以使用函式呼叫而不是使用迴圈跳轉。</p>
</div>
<h2 id="語法">語法</h2>
diff --git a/files/zh-tw/web/javascript/reference/statements/let/index.html b/files/zh-tw/web/javascript/reference/statements/let/index.html
index f3170bb603..7c0b50b552 100644
--- a/files/zh-tw/web/javascript/reference/statements/let/index.html
+++ b/files/zh-tw/web/javascript/reference/statements/let/index.html
@@ -165,8 +165,8 @@ let i = 10;</pre>
<h3 id="Another_example_of_temporal_dead_zone_combined_with_lexical_scoping">Another example of temporal dead zone combined with lexical scoping</h3>
-<p>Due to lexical scoping, the identifier<strong> "foo"</strong> inside the expression <code>(foo + 55)</code> evaluates to the <u>if block's foo</u>, and <strong>not</strong> the <u>overlying variable foo</u> with the value of 33.<br>
- In that very line, the <u>if block's "foo"</u> has already been created in the lexical environment, but has not yet reached (and <strong>terminated</strong>) its initialization (which is part of the statement itself): it's still in the temporal dead zone.</p>
+<p>Due to lexical scoping, the identifier<strong> "foo"</strong> inside the expression <code>(foo + 55)</code> evaluates to the <em>if block's foo</em>, and <strong>not</strong> the <em>overlying variable foo</em> with the value of 33.<br>
+ In that very line, the <em>if block's "foo"</em> has already been created in the lexical environment, but has not yet reached (and <strong>terminated</strong>) its initialization (which is part of the statement itself): it's still in the temporal dead zone.</p>
<pre class="brush: js example-bad">function test(){
var foo = 33;
@@ -176,7 +176,7 @@ let i = 10;</pre>
}
test();</pre>
-<p>This phenomenon may confuse you in a situation like the following. The instruction <code>let n of n.a</code> is already inside the private scope of the <u>for loop's block</u>, hence the identifier<strong> "n.a"</strong> is resolved to the property 'a' of the <u>'n' object located in the first part of the instruction itself</u> ("let n"), which is still in the temporal dead zone since its declaration statement has not been reached and <strong>terminated</strong>.</p>
+<p>This phenomenon may confuse you in a situation like the following. The instruction <code>let n of n.a</code> is already inside the private scope of the <em>for loop's block</em>, hence the identifier<strong> "n.a"</strong> is resolved to the property 'a' of the <em>'n' object located in the first part of the instruction itself</em> ("let n"), which is still in the temporal dead zone since its declaration statement has not been reached and <strong>terminated</strong>.</p>
<pre class="brush: js example-bad">function go(n) {
// n here is defined!
diff --git a/files/zh-tw/web/javascript/reference/statements/return/index.html b/files/zh-tw/web/javascript/reference/statements/return/index.html
index e207c2c6f3..be8cb4c346 100644
--- a/files/zh-tw/web/javascript/reference/statements/return/index.html
+++ b/files/zh-tw/web/javascript/reference/statements/return/index.html
@@ -58,7 +58,7 @@ a + b;
<p>主控台會警告「unreachable code after return statement」(在 return 宣告後面有無法抵達的程式碼)。</p>
-<div class="note">從 Gecko 40 {{geckoRelease(40)}} 開始,如果主控台發現在 return 宣告後面有無法抵達的程式碼,就會顯示警告。</div>
+<div class="notecard note"><p><strong>備註:</strong>從 Gecko 40 {{geckoRelease(40)}} 開始,如果主控台發現在 return 宣告後面有無法抵達的程式碼,就會顯示警告。</p></div>
<p>要避免 ASI 問題,可以添加括號:</p>
diff --git a/files/zh-tw/web/javascript/reference/statements/throw/index.html b/files/zh-tw/web/javascript/reference/statements/throw/index.html
index 9994f8c58c..82ba6282da 100644
--- a/files/zh-tw/web/javascript/reference/statements/throw/index.html
+++ b/files/zh-tw/web/javascript/reference/statements/throw/index.html
@@ -145,87 +145,11 @@ e = verifyZipCode('95060 1234'); // returns 95060 1234
<h2 id="規範">規範</h2>
-<table class="standard-table">
- <tbody>
- <tr>
- <th scope="col">Specification</th>
- <th scope="col">Status</th>
- <th scope="col">Comment</th>
- </tr>
- <tr>
- <td>{{SpecName('ES3')}}</td>
- <td>{{Spec2('ES3')}}</td>
- <td>Initial definition. Implemented in JavaScript 1.4</td>
- </tr>
- <tr>
- <td>{{SpecName('ES5.1', '#sec-12.13', 'throw statement')}}</td>
- <td>{{Spec2('ES5.1')}}</td>
- <td> </td>
- </tr>
- <tr>
- <td>{{SpecName('ES6', '#sec-throw-statement', 'throw statement')}}</td>
- <td>{{Spec2('ES6')}}</td>
- <td> </td>
- </tr>
- <tr>
- <td>{{SpecName('ESDraft', '#sec-throw-statement', 'throw statement')}}</td>
- <td>{{Spec2('ESDraft')}}</td>
- <td> </td>
- </tr>
- </tbody>
-</table>
+{{Specifications}}
<h2 id="瀏覽器相容性">瀏覽器相容性</h2>
-<p>{{CompatibilityTable}}</p>
-
-<div>
-<table class="compat-table">
- <tbody>
- <tr>
- <th>Feature</th>
- <th>Chrome</th>
- <th>Firefox (Gecko)</th>
- <th>Internet Explorer</th>
- <th>Opera</th>
- <th>Safari</th>
- </tr>
- <tr>
- <td>Basic support</td>
- <td>{{CompatVersionUnknown}}</td>
- <td>{{CompatVersionUnknown}}</td>
- <td>{{CompatVersionUnknown}}</td>
- <td>{{CompatVersionUnknown}}</td>
- <td>{{CompatVersionUnknown}}</td>
- </tr>
- </tbody>
-</table>
-</div>
-
-<div>
-<table class="compat-table">
- <tbody>
- <tr>
- <th>Feature</th>
- <th>Android</th>
- <th>Chrome for Android</th>
- <th>Firefox Mobile (Gecko)</th>
- <th>IE Mobile</th>
- <th>Opera Mobile</th>
- <th>Safari Mobile</th>
- </tr>
- <tr>
- <td>Basic support</td>
- <td>{{CompatVersionUnknown}}</td>
- <td>{{CompatVersionUnknown}}</td>
- <td>{{CompatVersionUnknown}}</td>
- <td>{{CompatVersionUnknown}}</td>
- <td>{{CompatVersionUnknown}}</td>
- <td>{{CompatVersionUnknown}}</td>
- </tr>
- </tbody>
-</table>
-</div>
+{{Compat}}
<h2 id="參見">參見</h2>
diff --git a/files/zh-tw/web/javascript/reference/statements/var/index.html b/files/zh-tw/web/javascript/reference/statements/var/index.html
index 2ef07a3afa..c3a4712301 100644
--- a/files/zh-tw/web/javascript/reference/statements/var/index.html
+++ b/files/zh-tw/web/javascript/reference/statements/var/index.html
@@ -155,87 +155,11 @@ console.log(typeof y); // undefined as y is local to function a</pre>
<h2 id="規範">規範</h2>
-<table class="standard-table">
- <tbody>
- <tr>
- <th scope="col">Specification</th>
- <th scope="col">Status</th>
- <th scope="col">Comment</th>
- </tr>
- <tr>
- <td>{{SpecName('ES1')}}</td>
- <td>{{Spec2('ES1')}}</td>
- <td>Initial definition. Implemented in JavaScript 1.0</td>
- </tr>
- <tr>
- <td>{{SpecName('ES5.1', '#sec-12.2', 'var statement')}}</td>
- <td>{{Spec2('ES5.1')}}</td>
- <td> </td>
- </tr>
- <tr>
- <td>{{SpecName('ES6', '#sec-variable-statement', 'variable statement')}}</td>
- <td>{{Spec2('ES6')}}</td>
- <td> </td>
- </tr>
- <tr>
- <td>{{SpecName('ESDraft', '#sec-variable-statement', 'variable statement')}}</td>
- <td>{{Spec2('ESDraft')}}</td>
- <td> </td>
- </tr>
- </tbody>
-</table>
+{{Specifications}}
<h2 id="瀏覽器相容性">瀏覽器相容性</h2>
-<p>{{CompatibilityTable}}</p>
-
-<div>
-<table class="compat-table">
- <tbody>
- <tr>
- <th>Feature</th>
- <th>Chrome</th>
- <th>Firefox (Gecko)</th>
- <th>Internet Explorer</th>
- <th>Opera</th>
- <th>Safari</th>
- </tr>
- <tr>
- <td>Basic support</td>
- <td>{{CompatVersionUnknown}}</td>
- <td>{{CompatVersionUnknown}}</td>
- <td>{{CompatVersionUnknown}}</td>
- <td>{{CompatVersionUnknown}}</td>
- <td>{{CompatVersionUnknown}}</td>
- </tr>
- </tbody>
-</table>
-</div>
-
-<div>
-<table class="compat-table">
- <tbody>
- <tr>
- <th>Feature</th>
- <th>Android</th>
- <th>Chrome for Android</th>
- <th>Firefox Mobile (Gecko)</th>
- <th>IE Mobile</th>
- <th>Opera Mobile</th>
- <th>Safari Mobile</th>
- </tr>
- <tr>
- <td>Basic support</td>
- <td>{{CompatVersionUnknown}}</td>
- <td>{{CompatVersionUnknown}}</td>
- <td>{{CompatVersionUnknown}}</td>
- <td>{{CompatVersionUnknown}}</td>
- <td>{{CompatVersionUnknown}}</td>
- <td>{{CompatVersionUnknown}}</td>
- </tr>
- </tbody>
-</table>
-</div>
+{{Compat}}
<h2 id="參見">參見</h2>