JavaScript Object Oriented Programming: Early and Late Binding

JavaScript 在呼叫的時候設定 this 的值,而這個 this 的值有可能不是我們預期的結果。下面有幾個範例。

javascript


JavaScript Object Oriented Programming: Exceptions

「例外(Exceptions)」是一個特別且重要的處理錯誤的方法。

ReferenceError NaN javascript


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