JavaScript Object Oriented Programming: Factory Constructor Pattern
08 Feb 2016Factory Constructor Pattern 不使用 new 來宣告新物件,新物件用 function call 來建立。
Factory Constructor Pattern 不使用 new 來宣告新物件,新物件用 function call 來建立。
在 pseudo-classical pattern 中,物件是由「建構子」(constructor)這個函式所建立,並把 method 放到建構子的 prototype 中。
Native JavaScript 物件將 method 存在 prototype 中。例如:當一個新的物件被建立,內容為空,但為何可以使用 toString 這個 method?