class Animal {
constructor(name) {
this.name = name;
}
speak() {
console.log(`${this.name} makes a noise.`);
}
}
class Dog extends Animal {
constructor(name) {
super(name); // вызов конструктора родительского класса
}
speak() {
console.log(`${this.name} barks.`);
}
}
let animal = {
speak() {
console.log(`${this.name} makes a noise.`);
}
};
let dog = Object.create(animal);
dog.name = 'Fido';
dog.speak = function() {
console.log(`${this.name} barks.`);
}