JavaScript classes with getter and setter cause RangeError: Maximum call stack size exceeded

前端 未结 5 466
南方客
南方客 2020-11-30 11:12

I am currently experimenting with ECMA6 classes. My current class looks like the following

class Player {
  constructor(id) {
    this.id = id;
    this.cash         


        
5条回答
  •  没有蜡笔的小新
    2020-11-30 11:33

    cash represents the getter/setter, _cash is the 'private' property.

      set cash(value) { // line 19
          this._cash = value; // line 20
      }
    

    Have a look at this page for a clear example.

提交回复
热议问题