Uncaught TypeError: Cannot set property playerNo of # which has only a getter on line 4

You have recursion with setting playerNo.

In the playerNo setter, try setting this._playerNo = 0.

In the rest of the code, continue to make a distinction between the name of the setter method and the internal property that stores the data.


You can use a getter as means of "protected" property, one you can only read from the outside and it has no setter ...

However, in your code you were trying to call a non-existing setter this.playerNo = playerNo and within your getter you were recursively referring to the same getter return this.playerNo instead of using the hidden this._playerNo property within it (same in your constructor) - hence the stack overflow error.

Remember that with getters/setters you need some extra storage for your value, such as the private _playerNo property (unless you're delegating the storage elsewhere).