<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
// 父类
class Student {
constructor(name) {
this.name = name;
}
sayHi() {
alert('Hello')
}
}
//继承、子类
class elementaryStudent extends Student {
constructor(name, age) {
super(name);
this.age = age;
}
sayHi() {
alert('Hi, I am an elementary student')
}
}
// 实例化
var lily = new Student('Lily')
var Tom = new elementaryStudent('Tom', 24)
</script>
</head>
<body>
</body>
</html>
Tom.age // 24
lily.name // Lily