class、extends的用法
class Animal{
constructor(name, age) {
this.name = name;
this.age = age;
}
getName() {
return this.name
}
}
// Dog类继承Animal类
class Dog extends Animal{
constructor(name, age, sexual, color) {
super(name, age);
this.sexual= sexual;
this.color= color;
}
getColor() {
return this.color;
}
}
super( ) 代表构造函数的继承 在ES5中是使用call/apply
项目中的使用案例 有状态组件