【发布时间】:2017-01-25 22:13:48
【问题描述】:
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;
};
下一行产生错误(对象原型未定义,必须为对象或空)。据我所知,这是因为 Shape 是“命名空间”。
sl.Rectangle.protoype = Object.create(sl.Shape.protoype);
sl.Rectangle.protoype.constructor = sl.Rectangle;
我该如何正确地做到这一点?
【问题讨论】:
标签: javascript class namespaces prototype extend