我正在尝试原型(prototype)继承,当我在控制台中输入它时,我没有收到错误,但它似乎没有正确继承。
var organism = {
hasCellDivision: true
};
var animals = Object.create(organism);
animals.hasNervousSystem = true;
var mammals = Object.create(animals);
mammals.legs = 4, hasBrain = true, hasBlood = true, heads = 1;
var plants = Object.create(organism);
plants.hasNervousSystem = false;
var whale = Object.create(mammals);
whale.leg = 0;
var insects = Object.create(mammals);
insects.legs = 6, hasBrain = false, hasGanglia = true;
最佳答案
我认为问题出在这里
var mammals = Object.create(animals);
mammals.legs = 4, hasBrain = true, hasBlood = true, heads = 1;
应该
var mammals = Object.create(animals);
mammals.legs = 4, mammals.hasBrain = true, mammals.hasBlood = true, mammals.heads = 1;
关于javascript - 为什么我的鲸鱼对象没有继承哺乳动物对象的属性?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37671112/