From f45e9e070c93ebbd83d488bdd775987a4d75c201 Mon Sep 17 00:00:00 2001 From: t7yang Date: Mon, 10 Jan 2022 08:38:08 +0800 Subject: fix yari h2m dry run errors --- .../control_flow_and_error_handling/index.html | 6 +- .../guide/details_of_the_object_model/index.html | 24 +- .../guide/expressions_and_operators/index.html | 10 +- .../web/javascript/guide/functions/index.html | 6 +- .../javascript/guide/grammar_and_types/index.html | 8 +- files/zh-tw/web/javascript/guide/index.html | 250 +++++++++++++-------- .../guide/indexed_collections/index.html | 14 +- .../web/javascript/guide/introduction/index.html | 2 +- .../guide/iterators_and_generators/index.html | 4 +- .../web/javascript/guide/using_promises/index.html | 6 +- .../guide/working_with_objects/index.html | 2 +- 11 files changed, 197 insertions(+), 135 deletions(-) (limited to 'files/zh-tw/web/javascript/guide') diff --git a/files/zh-tw/web/javascript/guide/control_flow_and_error_handling/index.html b/files/zh-tw/web/javascript/guide/control_flow_and_error_handling/index.html index c140d1a991..b26a576309 100644 --- a/files/zh-tw/web/javascript/guide/control_flow_and_error_handling/index.html +++ b/files/zh-tw/web/javascript/guide/control_flow_and_error_handling/index.html @@ -229,7 +229,9 @@ throw true; // True/False throw {toString: function() { return "我是物件!"; } }; -
備註:您可以在拋出例外時指定物件。 然後,可以在 catch 區塊中引用對象的屬性。
+
+

備註:您可以在拋出例外時指定物件。 然後,可以在 catch 區塊中引用對象的屬性。

+
// 創建類型爲 UserException 的物件
 function UserException(message) {
@@ -398,7 +400,7 @@ catch (e) {
  
  • settled:已完成,表示 Promise 狀態為已實現或已拒絕,但不是等待中。
  • -

    +

    promises

    使用 XHR 載入圖檔

    diff --git a/files/zh-tw/web/javascript/guide/details_of_the_object_model/index.html b/files/zh-tw/web/javascript/guide/details_of_the_object_model/index.html index ae69cc38f4..ba436da83c 100644 --- a/files/zh-tw/web/javascript/guide/details_of_the_object_model/index.html +++ b/files/zh-tw/web/javascript/guide/details_of_the_object_model/index.html @@ -40,7 +40,7 @@ translation_of: Web/JavaScript/Guide/Details_of_the_Object_Model

    下面的表格列出了上述區別。本節的後續部分將描述有關使用 JavaScript 構建函數和原型創建物件層級結構的詳細資訊,並與在 Java 中的做法做對比。

    - +
    @@ -80,7 +80,7 @@ translation_of: Web/JavaScript/Guide/Details_of_the_Object_Model

    本節的餘下部分將使用如下圖所示的僱員層級結構。

    -

    +

    圖例 8.1:一個簡單的物件層級

    @@ -102,7 +102,7 @@ translation_of: Web/JavaScript/Guide/Details_of_the_Object_Model

    在 真實的應用程式中,您很可能想定義允許在創建物件時給出屬性值的建構函數。(參見 更靈活的建構函數 獲得進一步的資訊)。對於現在而言,這些簡單的定義示範了繼承是如何發生的。

    -

    figure8.2.png
    +

    figure8.2.png
    圖例 8.2:Employee 物件定義

    以下 Employee 的 Java 和 JavaScript 的定義相類似。唯一的不同是在 Java 中需要指定每個屬性的類型,而在 JavaScript 中則不必指定,同時 Java 的類必須創建一個顯式的建構函數方法。

    @@ -238,8 +238,8 @@ public class Engineer extends WorkerBee {

    {{ note('術語 實例(instance)在 基於類的語言中具有特定的技術含義。在這些語言中,實例是指類的個體成員,與類有著根本性的不同。在 JavaScript 中,“實例”並不具有這種技術含義,因為 JavaScript 中不存在類和實例之間的這種差異。然而,在談論 JavaScript 時,“實例”可以非正式地用於表示用特定的建構函數創建的物件。所以,在這個例子中,你可以非正式地 janeEngineer 的一個實例。與之類似,儘管術語父(parent)子(child)祖先(ancestor),和後代(descendant)在 JavaScript 中並沒有正式的含義,您可以非正式地使用這些術語用於指代原型鏈中處於更高層次或者更低層次的物件。') }}

    -

    figure8.3.png
    - 圖例 8.3:通過簡單的定義創建物件

    +

    figure8.3.png
    + 圖例 8.3:通過簡單的定義創建物件

    物件的屬性

    @@ -285,15 +285,15 @@ mark.projects = ["navigator"];

    一旦 JavaScript 執行該語句,則 mark 物件也將具有 specialty 屬性,其值為 "none"。下圖展現了在 Employee 原型中添加該屬性,然後在 Engineer 的原型中重載該屬性的效果。

    -


    +


    Figure 8.4: Adding properties

    -

    更靈活的建構函數

    +

    更靈活的建構函數

    到目前為止所展現的建構函數不允許在創建新的實例時指定屬性值。正如 Java 一樣,可以為建構函數提供參數以便初始化實例的屬性值。下圖展現其中一種做法。

    -


    - Figure 8.5: Specifying properties in a constructor, take 1

    +


    + Figure 8.5: Specifying properties in a constructor, take 1

    下面的表格中羅列了這些物件在 Java 和 JavaScript 中的定義。

    @@ -413,7 +413,7 @@ jane.machine == "belau"

    到目前為止,建構函數已經能夠創建一個普通物件,然後為新物件指定本地的屬性和屬性值。您還可以通過直接調用原型鏈上的更高層次物件的建構函數,讓建構函數添加更多的屬性。下面的圖例展現這種新定義。

    -


    +


    Figure 8.6 Specifying properties in a constructor, take 2

    讓我們仔細看看這些定義的其中之一。以下是 Engineer 建構函數的定義:

    @@ -607,7 +607,9 @@ chris.__proto__.__proto__.__proto__.__proto__.__proto__ == null; } -
    Note: 在上面的實現中,檢查物件的類型是否為 "xml" 的目的在於解決新近版本的 JavaScript 中表達 XML 物件的特異之處。如果您想瞭解其中瑣碎細節,可以參考 {{ bug(634150) }}。
    +
    +

    備註: 在上面的實現中,檢查物件的類型是否為 "xml" 的目的在於解決新近版本的 JavaScript 中表達 XML 物件的特異之處。如果您想瞭解其中瑣碎細節,可以參考 {{ bug(634150) }}。

    +
    instanceOf (chris, Engineer)
     instanceOf (chris, WorkerBee)
    diff --git a/files/zh-tw/web/javascript/guide/expressions_and_operators/index.html b/files/zh-tw/web/javascript/guide/expressions_and_operators/index.html
    index 4e0c8655bc..77075cdd2e 100644
    --- a/files/zh-tw/web/javascript/guide/expressions_and_operators/index.html
    +++ b/files/zh-tw/web/javascript/guide/expressions_and_operators/index.html
    @@ -212,8 +212,8 @@ var var2 = 4;
      
     
    表 8.1 基於類(Java)和基於原型(JavaScript)的物件系統的比較
    -
    -

    筆記: (=>)不是運算子,是 箭頭函式。

    +
    +

    備註:(=>)不是運算子,是 箭頭函式。

    算術運算子

    @@ -226,7 +226,7 @@ var var2 = 4;

    除了標準的算術運算子外 (+, -, * /), JavaScript 提供以下表中的算術運算子:

    - +
    @@ -388,7 +388,7 @@ var var2 = 4;

    移動運算子在下表被列出.

    -
    算術運算子
    +
    @@ -421,7 +421,7 @@ var var2 = 4;

    邏輯運算子 通常被用於布林(邏輯)值; 使用於 布林(邏輯)值時, 它們會回傳布林型態的值。 然而,&&|| 運算子實際上是回傳兩指定運算元之一,因此用於非布林型態值時,它可能會回傳一個非布林型態的值。 邏輯運算子將在下表中被詳細解釋。

    -
    位元移動運算子
    +
    diff --git a/files/zh-tw/web/javascript/guide/functions/index.html b/files/zh-tw/web/javascript/guide/functions/index.html index f71ccfa1e9..af19983b6f 100644 --- a/files/zh-tw/web/javascript/guide/functions/index.html +++ b/files/zh-tw/web/javascript/guide/functions/index.html @@ -72,12 +72,8 @@ y = mycar.make; // y 的值還是 "Honda"
    var square = function(number) {return number * number};
     var x = square(4) //x 的值為 16
    -
    必要時,函式名稱可與函式表達式同時存在,並且可以用於在函式內部代指其本身(遞迴):
    -
     
    -
    -
    var factorial = function fac(n) {return n<2 ? 1 : n*fac(n-1)};
     
     console.log(factorial(3));
    @@ -150,7 +146,7 @@ e = factorial(5); // e gets the value 120
     
     

    There are other ways to call functions. There are often cases where a function needs to be called dynamically, or the number of arguments to a function vary, or in which the context of the function call needs to be set to a specific object determined at runtime. It turns out that functions are, themselves, objects, and these objects in turn have methods (see the Function object). One of these, the apply() method, can be used to achieve this goal.

    -

    Function scope

    +

    Function scope

    Variables defined inside a function cannot be accessed from anywhere outside the function, because the variable is defined only in the scope of the function. However, a function can access all variables and functions defined inside the scope in which it is defined. In other words, a function defined in the global scope can access all variables defined in the global scope. A function defined inside another function can also access all variables defined in it's parent function and any other variable to which the parent function has access.

    diff --git a/files/zh-tw/web/javascript/guide/grammar_and_types/index.html b/files/zh-tw/web/javascript/guide/grammar_and_types/index.html index 04f4818cdb..a5200c39ec 100644 --- a/files/zh-tw/web/javascript/guide/grammar_and_types/index.html +++ b/files/zh-tw/web/javascript/guide/grammar_and_types/index.html @@ -335,8 +335,8 @@ y = 42 + " is the answer" // "42 is the answer"
    var coffees = ['French Roast', 'Colombian', 'Kona'];
     
    -
    -

    Note : An array literal is a type of object initializer. See Using Object Initializers.

    +
    +

    Note: An array literal is a type of object initializer. See Using Object Initializers.

    If an array is created using a literal in a top-level script, JavaScript interprets the array each time it evaluates the expression containing the array literal. In addition, a literal used in a function is created each time the function is called.

    @@ -354,8 +354,8 @@ y = 42 + " is the answer" // "42 is the answer"

    If you include a trailing comma at the end of the list of elements, the comma is ignored. In the following example, the length of the array is three. There is no myList[3]. All other commas in the list indicate a new element.

    -
    -

    Note : Trailing commas can create errors in older browser versions and it is a best practice to remove them.

    +
    +

    Note: Trailing commas can create errors in older browser versions and it is a best practice to remove them.

    var myList = ['home', , 'school', ];
    diff --git a/files/zh-tw/web/javascript/guide/index.html b/files/zh-tw/web/javascript/guide/index.html
    index c7ba53958a..23d3b2a340 100644
    --- a/files/zh-tw/web/javascript/guide/index.html
    +++ b/files/zh-tw/web/javascript/guide/index.html
    @@ -11,106 +11,168 @@ translation_of: Web/JavaScript/Guide
     
     

    本指南區分成以下數個章節:

    -
    -
    -

    Note : in the above code, arrayLength must be a Number. Otherwise, an array with a single element (the provided value) will be created. Calling arr.length will return arrayLength, but the array actually contains empty (undefined) elements. Running a {{jsxref("Statements/for...in","for...in")}} loop on the array will return none of the array's elements.

    +
    +

    Note: in the above code, arrayLength must be a Number. Otherwise, an array with a single element (the provided value) will be created. Calling arr.length will return arrayLength, but the array actually contains empty (undefined) elements. Running a {{jsxref("Statements/for...in","for...in")}} loop on the array will return none of the array's elements.

    In addition to a newly defined variable as shown above, arrays can also be assigned as a property of a new or an existing object:

    @@ -79,8 +79,8 @@ emp[1] = 'Phil Lesh'; emp[2] = 'August West';
    -
    -

    Note : if you supply a non-integer value to the array operator in the code above, a property will be created in the object representing the array, instead of an array element.

    +
    +

    Note: if you supply a non-integer value to the array operator in the code above, a property will be created in the object representing the array, instead of an array element.

    var arr = [];
    @@ -104,8 +104,8 @@ var myArray = ['Mango', 'Apple', 'Orange'];
     
     

    You then refer to the first element of the array as myArray[0] and the second element of the array as myArray[1]. The index of the elements begins with zero.

    -
    -

    Note : the array operator (square brackets) is also used for accessing the array's properties (arrays are also objects in JavaScript). For example,

    +
    +

    Note: the array operator (square brackets) is also used for accessing the array's properties (arrays are also objects in JavaScript). For example,

    var arr = ['one', 'two', 'three'];
    @@ -433,7 +433,7 @@ Row 3: [3, 0] [3, 1] [3, 2] [3, 3]
     
     

    To achieve maximum flexibility and efficiency, JavaScript typed arrays split the implementation into buffers and views. A buffer (implemented by the {{jsxref("ArrayBuffer")}} object) is an object representing a chunk of data; it has no format to speak of, and offers no mechanism for accessing its contents. In order to access the memory contained in a buffer, you need to use a view. A view provides a context — that is, a data type, starting offset, and number of elements — that turns the data into an actual typed array.

    -

    Typed arrays in an ArrayBuffer

    +

    Typed arrays in an ArrayBuffer

    ArrayBuffer

    diff --git a/files/zh-tw/web/javascript/guide/introduction/index.html b/files/zh-tw/web/javascript/guide/introduction/index.html index ae980e77b0..fee75789ba 100644 --- a/files/zh-tw/web/javascript/guide/introduction/index.html +++ b/files/zh-tw/web/javascript/guide/introduction/index.html @@ -154,7 +154,7 @@ translation_of: Web/JavaScript/Guide/Introduction
    Logical operators
    -
    注意:ECMA-262 第2版是由已修正錯誤的第1版並加上些微的更動構成。現今由 Ecma International 的 TC39 工作組(TC39 Working Group)所發行的版本是 ECMAScript 5.1版
    +

    備註:ECMA-262 第2版是由已修正錯誤的第1版並加上些微的更動構成。現今由 Ecma International 的 TC39 工作組(TC39 Working Group)所發行的版本是 ECMAScript 5.1版

    JavaScript Reference 指出了哪些 JavaScript 的特性是相容於 ECMAScript 的。

    diff --git a/files/zh-tw/web/javascript/guide/iterators_and_generators/index.html b/files/zh-tw/web/javascript/guide/iterators_and_generators/index.html index 8c53a56eb2..5d5fb327c6 100644 --- a/files/zh-tw/web/javascript/guide/iterators_and_generators/index.html +++ b/files/zh-tw/web/javascript/guide/iterators_and_generators/index.html @@ -70,8 +70,8 @@ console.log("Iterated over sequence of size: ", result.value); // 5
    -
    -

    It is not possible to know reflectively whether a particular object is an iterator. If you need to do this, use Iterables.

    +
    +

    Note: It is not possible to know reflectively whether a particular object is an iterator. If you need to do this, use Iterables.

    Generator functions

    diff --git a/files/zh-tw/web/javascript/guide/using_promises/index.html b/files/zh-tw/web/javascript/guide/using_promises/index.html index 1df6376ffd..71b99084e7 100644 --- a/files/zh-tw/web/javascript/guide/using_promises/index.html +++ b/files/zh-tw/web/javascript/guide/using_promises/index.html @@ -11,7 +11,7 @@ translation_of: Web/JavaScript/Guide/Using_promises

    舉例來說,下方的範例若用舊方式應該會有兩個 Callback,並根據成功或失敗來決定使用哪個:

    -
    function successCallback(result) {
    +
    function successCallback(result) {
       console.log("It succeeded with " + result);
     }
     
    @@ -24,12 +24,12 @@ doSomething(successCallback, failureCallback);
     
     

    而新作法會回傳一個 Promise,這樣你就可以附加 Callback:

    -
    let promise = doSomething();
    +
    let promise = doSomething();
     promise.then(successCallback, failureCallback);

    再簡單點:

    -
    doSomething().then(successCallback, failureCallback);
    +
    doSomething().then(successCallback, failureCallback);

    我們稱之為 非同步函數呼叫。這個做法有許多好處,我們接下來看看。

    diff --git a/files/zh-tw/web/javascript/guide/working_with_objects/index.html b/files/zh-tw/web/javascript/guide/working_with_objects/index.html index ec531a1004..31b9403a01 100644 --- a/files/zh-tw/web/javascript/guide/working_with_objects/index.html +++ b/files/zh-tw/web/javascript/guide/working_with_objects/index.html @@ -124,7 +124,7 @@ myCar.year = 1969

    JavaScript has a number of predefined objects. In addition, you can create your own objects. You can create an object using an object initializer. Alternatively, you can first create a constructor function and then instantiate an object invoking that function in conjunction with the new operator.

    -

    Using object initializers

    +

    Using object initializers

    In addition to creating objects using a constructor function, you can create objects using an object initializer. Using object initializers is sometimes referred to as creating objects with literal notation. "Object initializer" is consistent with the terminology used by C++.

    -- cgit v1.2.3-54-g00ecf