// 父类 class Animal { constructor(name) { this.name = name; } speak() { return "some animal sound"; } } // 子类 class Dog extends Animal { speak() { return this.name +": Woof!"; } } // 子类 class Cat extends Animal { speak() { return this.name +": Meow!"; } } // 使用 let dog = new Dog("阿狗"); let cat = new Cat("阿猫"); console.log(dog.speak()); // 输出: Woof! console.log(cat.speak()); // 输出: Meow!