小编Ser*_*aev的帖子

ES6 super()在构造函数中实际做了什么?

!Hola,amigos.我有这个小类继承结构

class Point {
    constructor(x, y) {
        this.x = x;
        this.y = y;
    }
    toString() {
        return '(' + this.x + ', ' + this.y + ')';
    }
}

class ColorPoint extends Point {
    constructor(x, y, color) {
        super(x, y); 
        this.color = color;
    }
    toString() {
        return super.toString() + ' in ' + this.color; 
    }
}

let newObj = new ColorPoint(25, 8, 'green');
Run Code Online (Sandbox Code Playgroud)

它汇编到这个jsfiddle

我以愚蠢的方式了解它在es6中是如何工作的.但是有人可以解释它在es5中如何工作.以更简单的形式.

javascript constructor class super ecmascript-6

6
推荐指数
1
解决办法
3567
查看次数

标签 统计

class ×1

constructor ×1

ecmascript-6 ×1

javascript ×1

super ×1