I am currently experimenting with ECMA6 classes. My current class looks like the following
class Player {
constructor(id) {
this.id = id;
this.cash
You are calling recursively your getter.
It follows a possible alternative:
class Player {
constructor(id) {
this.id = id;
this._cash = 350;
}
get cash() {
return this._cash;
}
set cash(value) {
this._cash = value;
}
};
Another one using Object.defineProperty
:
class Player {
constructor(id) {
this.id = id;
var _cash = 350;
Object.defineProperty(this, 'cash', {
get: function() {
return _cash;
}
set: function(v) {
_cash = v;
}
});
}
};