ES6 class

104 阅读1分钟

1、class中子类继承父类,必须在constructor构造函数中添加super()来继承父类的this,否则实例化时,子类得不到this对象;

2、class中的方法通过return this可以实现方法的链式调用

class A extends B{
    constructor(x,y,color){
        super(x,y);
        this.color=color;
    }
    func1(){
        console.log("func1");
        return this;
    }
    func2(){
        console.log("func2");
        return this;
    }
}