一、代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
function Student(name) {
this.name = name;
}
Student.prototype.hello = function () {
alert("Hello Massimo");
};
class Student{
constructor(name){
this.name = name;
}
hello(){
alert("Hello Massimo");
}
}
var zhangsan = new Student("zhangsan");
var lisi = new Student("lisi");
class XiaoStudent extends Student{
constructor(name,grade){
super(name);
this.grade = grade;
}
myGrade(){
alert("我是一名小学生");
}
}
</script>
</head>
<body>
</body>
</html>
二、原型链
