2010-04-11 39 views

回答

11

這給出了一個解釋http://phrogz.net/JS/Classes/OOPinJS2.html

特別

Cat.prototype = new Mammal();  // Here's where the inheritance occurs 
Cat.prototype.constructor=Cat;  // Otherwise instances of Cat would have a constructor of Mammal 
+3

感謝。 Javascript是一種非常奇怪的語言。 :) – Sake 2010-04-11 10:46:06

+2

是的。我個人不會使用名稱'constructor'來存儲構造函數,因爲'constructor'在JavaScript中已經有了含義。 (只是不是一個有用的。) – bobince 2010-04-11 11:35:04

相關問題