SOURCE

function Animal(name) {
    this.name = name;
}

Animal.prototype.play = function() {
    console.log(`${this.name} is playing`);
}
Animal.prototype.eat = function(food) {
    console.log(`${this.name} is eating ${food}`);
}

function Dog(name) {
    Animal.call(this, name);
    this.test = 'xxx';
}

Object.setPrototypeOf(Dog.prototype, Animal.prototype);
Dog.prototype.methods = function() {
    console.log('child methos');
}

const animal = new Animal('animal');
animal.play();

const dog = new Dog('dog');
dog.play();
dog.eat();
dog.methods();

class Animal {
    constructor(name) {
        this.name = name;
    }
    play() {
        console.log(`${this.name} is playing`);
    }
    eat() {
        console.log(`${this.name} is eating ${food}`);
    }
}

class Dog extends Animal {
    constructor (name) {
        super(name);
        this.test = 'xxxx';
    }
    methods() {
        console.log('child methos');
    }
}
console 命令行工具 X clear

                    
>
console