繁体   English   中英

为什么我的继承无效?

[英]Why isnt my inheritance working?

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;

您忘记将上下文参数传递给LivingThing

function Animal(name,sex,distance,description,attributes,health,level){
    LivingThing.call(this,name,sex,distance,attributes,health,level);
    this.description= description;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM