美文网首页
es6--Class类与继承的用法

es6--Class类与继承的用法

作者: 花拾superzay | 来源:发表于2020-01-14 16:04 被阅读0次

一个demo说明class类与继承的用法

//父类
class Point {
    //构造函数
    constructor(x, y) {
        this.x = x;
        this.y = y;
        return this
    }
    //原型
    toString() {
        return `(${this.x},${this.y})`
    }
}

//子类
class Subpoint extends Point {
    //子类构造函数
    constructor(x, y, z) {
        super(x, y);//先实例化父类属性
        this.z = z;
        return this
    }
    //子类原型
    toString1() {
        return `(${this.x},${this.y},${this.z})`
    }
}

相关文章

网友评论

      本文标题:es6--Class类与继承的用法

      本文链接:https://www.haomeiwen.com/subject/bwdaactx.html