相关疑难解决方法(0)

通过伪经典实例化(JavaScript)掌握原型继承

我正在尝试通过 JavaScript 使用继承来传递测试套件。下面是我到目前为止的代码片段:

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';

};
Run Code Online (Sandbox Code Playgroud)

我想从 Infant 类和eat 方法继承 food 属性,但我的尝试没有成功。我最初的想法是分配 this.Adolescent = Infant.food; 但这没有用。我知道我需要将 Infant 设置为 Superclass 但我正在转动我的轮子

javascript inheritance prototype decorator prototypal-inheritance

3
推荐指数
1
解决办法
299
查看次数