LivingThing.call
无法正常工作。在对象创建上创建的唯一属性是description属性。 - 为什么?我多次检查过这个问题,但有些东西一直让我不知所措。
function LivingThing(name,sex,distance,attributes,health,level=1){
this.name=name;
this.sex=sex;
this.distance= distance;
this.attributes=attributes;
this.health=health;
this.level= level;
}
function Animal(name,sex,distance,description,attributes,health,level){
LivingThing.call(name,sex,distance,attributes,health,level);
this.description= description;
}
Animal.prototype=Object.create(LivingThing.prototype);
Animal.prototype.constructor= Animal;
答案 0 :(得分:3)
您忘记将上下文参数传递给LivingThing
:
function Animal(name,sex,distance,description,attributes,health,level){
LivingThing.call(this,name,sex,distance,attributes,health,level);
this.description= description;
}