class 继承、super 与静态成员 | 星雨笔录

使用 extends、super 和 static 表达类型关系。

核心: extends 继承类、super() 初始化父类部分、static 定义属于类而非实例的成员。

最小示例:

class Animal { constructor(name) { this.name = name; } }
class Cat extends Animal { constructor(name) { super(name); } static type = '猫'; }
console.log(new Cat('咪咪').name, Cat.type);

学完能做: 使用 extends、super 和 static 表达类型关系。