谁能告诉我我做错了什么?继承不在JS中工作?
收到此错误:
this.parent.Thing is not a function
this.parent.Thing(x,y);
继承人的代码。
[Break On This Error] this.parent.Thing(x,y);
//Thing class start
function Thing(x, y){
this.x = x;
this.y = y;
}
Thing.prototype.setX = function(newX){
this.x = newX;
}
Thing.prototype.setY = function(newY){
this.y = newY;
}
Thing.prototype.getX = function(){
return this.x;
}
Thing.prototype.getY = function(){
return this.y;
}
//Thing class end
//player start
Player.prototype = new Thing();
Player.prototype.constructor=Player; // Otherwise instances of Cat would have a constructor of Mammal
Player.prototype.parent = Thing.prototype;
function Player(x, y){
this.parent.Thing(x,y);
}
//player end
var player = new Player(100,100);
从这里得到它:http://phrogz.net/js/classes/OOPinJS2.html – CyanPrime 2011-01-31 19:26:29
什么问题? – Pointy 2011-01-31 19:28:26