From 218934fa2ed1c702a6d3923d2aa2cc6b43c48684 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:43:23 -0500 Subject: initial commit --- files/zh-tw/glossary/constructor/index.html | 41 +++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 files/zh-tw/glossary/constructor/index.html (limited to 'files/zh-tw/glossary/constructor') diff --git a/files/zh-tw/glossary/constructor/index.html b/files/zh-tw/glossary/constructor/index.html new file mode 100644 index 0000000000..a920ec31f0 --- /dev/null +++ b/files/zh-tw/glossary/constructor/index.html @@ -0,0 +1,41 @@ +--- +title: 建構子 +slug: Glossary/Constructor +translation_of: Glossary/Constructor +--- +

建構子(constructor)屬於實做(instantiated)的指定 class {{glossary("object")}}。建構子概念可應用到大多數的{{glossary("OOP","物件導向")}}程式語言。基本上,{{glossary("JavaScript")}} 建構子用於在 {{glossary("class")}} 的實做(instance)聲明。

+ +

語法

+ +
// 這是個通用的建構子 class Default
+function Default() {
+}
+
+// 這是擁有幾個參數的過載建構子 class Overloaded
+function Overloaded(arg1, arg2, ...,argN){
+}
+
+ +

要呼叫 JavaScript 內的建構子 class ,請用 new 操作符給 {{glossary("variable")}} 宣告新的 {{glossary("object reference")}}。

+ +
function Default() {
+}
+
+// 新的 Default 物件參照被分派給局部變數 defaultReference
+var defaultReference = new Default();
+
+ +

深入理解

+ +

基本知識

+ + + +

技術資訊

+ + -- cgit v1.2.3-54-g00ecf