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();
本文介绍JavaScript中使用class关键字定义类的方法,并演示了如何通过extends实现类的继承,同时提供了具体的实例代码。
2072

被折叠的 条评论
为什么被折叠?



