小编IGD*_*Dev的帖子

JavaScript中的继承和超级

我在学习JavaScript的第3天.我遇到了这段代码:

class B {
    constructor(name) {
        this.name = name;
    }

    printn() {
        return this.name;
    }
}

class A extends B {
    constructor(name, age) {
        super(name);
        this._age = age;
    }

    get age() {
        return this._age;
    }

    printName(){
        return super.printn();
    }
}

let c = new A("Testing", "37");
Console.log(c.printn());
Run Code Online (Sandbox Code Playgroud)

任何人都可以解释这段代码的作用.什么是构造函数和super()关键字.我相信这是为了继承?我让谷歌找到了一些东西,但这似乎是最简单的例子,但很少有人参考.

我无法使用此代码.

javascript inheritance class super ecmascript-6

0
推荐指数
1
解决办法
362
查看次数

标签 统计

class ×1

ecmascript-6 ×1

inheritance ×1

javascript ×1

super ×1