From f7b137a3dff09fb8f976140d16029ad6ec5cf2b5 Mon Sep 17 00:00:00 2001
From: t7yang {{ note('術語 實例(instance)在 基於類的語言中具有特定的技術含義。在這些語言中,實例是指類的個體成員,與類有著根本性的不同。在 JavaScript 中,“實例”並不具有這種技術含義,因為 JavaScript 中不存在類和實例之間的這種差異。然而,在談論 JavaScript 時,“實例”可以非正式地用於表示用特定的建構函數創建的物件。所以,在這個例子中,你可以非正式地 jane
是 Engineer
的一個實例。與之類似,儘管術語父(parent),子(child),祖先(ancestor),和後代(descendant)在 JavaScript 中並沒有正式的含義,您可以非正式地使用這些術語用於指代原型鏈中處於更高層次或者更低層次的物件。') }}
到目前為止所展現的建構函數不允許在創建新的實例時指定屬性值。正如 Java 一樣,可以為建構函數提供參數以便初始化實例的屬性值。下圖展現其中一種做法。
-
- Figure 8.5: Specifying properties in a constructor, take 1
+ Figure 8.5: Specifying properties in a constructor, take 1
下面的表格中羅列了這些物件在 Java 和 JavaScript 中的定義。
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 a8eafbba5f..7299e5d1c6 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 @@ -304,7 +304,7 @@ y = 42 + " is the answer" // "42 is the answer"當代表數字的值以字串形式存在記憶體中,有些方法可用來將這種字串轉換成整數或浮點數。
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.
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