小编vco*_*rea的帖子

ECMAScript 6类属性下划线前缀

我见过的类模式几乎都是这样的:

class Foo {
    constructor(x, y, z) {
      this._x = x;
      this._y = y;
      this._z = z;
    }

    get x() {
      return this._x;
    }
    set x(value) {
      //I acctually do some stuff here
      this._x = value;
    }

    get y() {
      return this._y;
    }
    set y(value) {
      //I acctually do some stuff here
      this._y = value;
    }

    get z() {
      return this._z;
    }
    set z(value) {
      //I acctually do some stuff here
      this._z = value;
    }
}
Run Code Online (Sandbox Code Playgroud)

console.log(new Foo('x', 'y', 'z')) …

javascript node.js ecmascript-6 es6-class

6
推荐指数
2
解决办法
1785
查看次数

标签 统计

ecmascript-6 ×1

es6-class ×1

javascript ×1

node.js ×1