<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
</body>
</html>
<script>
class Person{
constructor(newId,newName) {
this.id = newId;
this.name = newName;
}
eat(){
console.log("eat()");
}
}
//class 子类名 extends 父类名
class Student extends Person{
constructor(newId,newName,newScore){
//super关键字等价于父类构造方法
super(newId,newName);
this.score = newScore;
}
}
let s = new Student(1,"老王",99);
console.log(s.id);
s.eat();
</script>
js中ES6的继承
最新推荐文章于 2024-04-09 10:34:22 发布