ecma6继承特性
https://blog.csdn.net/m0_37452696/article/details/78370504
继承特性1 - 实例成员继承 通过extends关键字实现继承 如果子类有构造器, 必须添加super()调用父类构造器 继承后子类实例便可使用父类实例的属性与方法
class Animal {
constructor(name, age, gender) {
this.name = name;
this.age = age;
this.gender = gender;
};
eat() {
console.log('都得吃啊!');
};
};
class Person extends Animal {
constructor(name, age, gender) {
super(name, age);
this.gender = gender;
};
say() {
console.log(`${this.name}今年${this.age}岁了${this.gender}`);
};
};
var xiaoming = new Person('小明', 14, '男');
xiaoming.eat();
xiaoming.say();
继承特性2 - 静态成员继承
class Animal {
static test() {
console.log('来自父类的静态方法');
};
};
class Person extends Animal {};
Person.test();