JavaScript Object Oriented Programming: Factory Constructor Pattern

Factory Constructor Pattern 不使用 new 來宣告新物件,新物件用 function call 來建立。

javascript


JavaScript Object Oriented Programming: All-in-one Constructor Pattern

所有的 method 和 property 都放在 consctructor 中,而不使用 prototype。

javascript prototype javascript


JavaScript Object Oriented Programming: Pseudo-Classical Pattern

在 pseudo-classical pattern 中,物件是由「建構子」(constructor)這個函式所建立,並把 method 放到建構子的 prototype 中。

javascript prototype javascript


JavaScript Object Oriented Programming: The instanceof operator

instanceof 允許檢查物件是否為給定的 constructor 所產生的。

operator 運算子 javascript


JavaScript Object Oriented Programming: The constructor property

物件有內建的屬性「constructor」,意即「參考建立此物件的 function」。

javascript


JavaScript Object Oriented Programming: Extending Natives

Native JavaScript 物件將 method 存在 prototype 中。例如:當一個新的物件被建立,內容為空,但為何可以使用 toString 這個 method?

javascript prototype javascript


JavaScript Object Oriented Programming: Prototypal Inheritance

對大多數的語言來說,它們擁有「Class」和「Object」,而 Class 繼承其它的Class。對於 JavaScript 來說,繼承是使用 prototype 來實作的,意即沒有 Class,而是由物件繼承其它的物件來達成繼承。

javascript prototype javascript