es6中的继承
- es6中的继承主要就是class继承
class A {
constructor(x) {
this.x = x
this.seyHello = function() {
}
}
aa = 123;
getx() {
console.log(this.x);
}
}
// 子类
class B extends A {
constructor(y) {
super(100);
this.y = y;
}
gety = function () {
console.log(this.y);
}
}
let b = new B(200)
console.log(b);
有constructor时,extends 和super必须一起使用,不然会报错
如果没有constructor时,浏览器会自己加上去