<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
class Person { //类
constructor(name) { //构造函数 : 对象初始化的时候执行的函数
this.name = name;
}
getName() {
console.log( this.name );
}
}
// 继承
class Student extends Person {
// 如果子类需要有自己的初始化过程,有自己的constructor函数,那么在子类的constructor就必须要调用父类构造函数
constructor(name, type) {
// super 表示父类
super(name);
// this.name = name;
this.type = type;
}
}
let s1 = new Student('莫涛', 'css');
</script>
</body>
</html>