咏竹莉
where there is a will,there is a way

super 类似于ES5语法中的call 继承

       class A {
            constructor(name) {
          console.log(name);    // xiaozhu
this.name = name; }
       getX() {
console.log(this.name)
      } } class B extends A { // extends 是ES6 中class 继承的方法 类似原型继承 constructor(age){, super(
'xiaozhu'); // l类似于call的继承: 在这里super 相当于把A的constructor 给执行了,并且让方法中的this是B 的实例, super 当中传递的实参都是给A中的constructor传递 } sing() { console.log( this.name,this.age) } } const b = new B() b.sing(); // xiaozhu 19

 

posted on 2021-04-27 18:00  咏竹莉  阅读(808)  评论(0)    收藏  举报