jjzjj

playerNo

全部标签

javascript - 未捕获的类型错误 : Cannot set property playerNo of# which has only a getter on line 4

我正在从使用旧的(函数和原型(prototype))hackyJavaScript类转向使用新的ES6类。我可能正在做一些愚蠢的事情,但我不确定为什么不允许我这样做:classPlayer{constructor(playerNo){this.playerNo=playerNo;}getplayerNo(){returnthis.playerNo;}setcards(playersCards){this.cards=playersCards;}getcards(){returnthis.cards;}}varsteve=newPlayer(1);它给我错误:UncaughtTypeEr