class Animal {constructor(name) {this.name = name;}speak() {console.log(`${this.name} makes a noise.`);}
}class Dog extends Animal {constructor(name, breed) {super(name); // 调用父类的构造函数this.breed = breed;}speak() {console.log(`${this.name} barks.`);}
}const dog = new Dog('Rex', 'Golden Retriever');
dog.speak(); // 输出: Rex barks.