【发布时间】:2016-04-10 07:31:00
【问题描述】:
我正在尝试通过 JavaScript 使用继承来通过测试套件。以下是我到目前为止的代码的 sn-p:
var Infant = function() {
this.age = 0;
this.color = 'pink';
this.food = 'milk';
};
Infant.prototype.eat = function(){
return this.eat;
}
var Adolescent = function() {
this.age = 5;
this.height = 'short';
this.job = 'keep on growing';
};
我想从 Infant 类和 eat 方法继承 food 属性,但我的尝试失败了。我最初的想法是分配 this.Adolescent = Infant.food;但这没有用。我知道我需要将 Infant 设置为 Superclass,但我正在旋转我的轮子
【问题讨论】:
标签: javascript inheritance prototype decorator prototypal-inheritance