super关键字
tips:子类会自动继承父类的方法
在继承的构造函数中super必须放在第一行
class Father{
constructor(x,y){
this.x=x;
this.y=y;
}
count(x,y){
console.log(x+y);
}
}
class Son extends Father{
constructor(x,y){
//在继承的构造函数中super必须放在第一行
super(x,y);
}
}
var son=new Son();
son.count(2,4)
demo
class Person{
constructor(name,age){
this.name=name;
this.age=age
}
sayName(){
console.log(this.name);
}
}
class Student extends Person{
constructor(name,age,skill){
super(name,age);
this.skill=skill;
}
}
var s=new Student("李思",19,"wechat")
s.sayName()
console.log(s);