JS学习笔记-class继承
- class关键字
是在ES6之后引入的
- 定义一个类,属性,方法
class student{
constructor(name){
this.name = name;
}
hello(){
alert('hello');
}
}
var alb = new student("alb");
var bbb = new student("bbb");
alb.hello();
- 继承
class student{
constructor(name){
this.name = name;
}
hello(){
alert('hello');
}
}
class priStu extends student{
constructor(name,score){
super(name);
this.score = score;
}
myScore(){
alert('我的成绩好');
}
}
var stu2 = new priStu("stu2",100);
stu2.myScore();