var sl = sl || {}
sl.Shape = function(){
this.x = 0;
this.y = 0;
};
sl.Shape.prototype.move = function(x,y){
this.x += x;
this.y += y;
};
sl.Rectangle = function(){
sl.Shape.call(this);
this.z = 0;
};
下一行產生錯誤(對象原型未定義,必須爲Object或null)。據我所見,這是因爲Shape是「命名空間」。如何在JavaScript中的命名空間內擴展一個類?
sl.Rectangle.protoype = Object.create(sl.Shape.protoype);
sl.Rectangle.protoype.constructor = sl.Rectangle;
如何正確地做到這一點?
感謝,帶我到凌晨4點,看看它,甚至在你寫了! – Daniela