
class A {
constructor(name) {
this.name = name;
}
sayHello() {
return this.name + " say Hello!";
}
}
class B extends A {
constructor(name, id) {
super(name);
this.id = id;
}
checkId(ID) {
return this.id === ID;
}
}
// 创建实例
let instanceB = new B("John", 123);
// 在网页上显示继承结果
document.write(instanceB.sayHello() + "<br>");
document.write("Check ID result: " + instanceB.checkId(123) + "<br>");