阅读背景:

简述RN组件constructor(){} 中加上 super()的作用_移动开发技术分享

来源:互联网 

首先通过下述例子了解在es6中实现继承:

class father{
    constructor(name) {
         this.name = name
    }
    
    printName() {
        console.log(this.name)
    }
}


class children extends father{
    constructor(name,age) {
        super(name) // super代表的是父类的构造函数
        this.age = age
    }

    printAge() {
        console.log(this.age)
    }
}

let jack = new children('jack',20)
    jack.printName()    //输出 : jack
    jack.printAge()    //输出 : 20class father{
    constr



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: