在 javascript 中,假设我做了一些这样的类:
class Player {
constructor(playerName, playerScore, playerTurn) {
this.playerName = playerName;
this.playerScore = playerScore;
this.playerTurn = playerTurn;
}
}
然后我创建一个播放器:
playerOne = new Player('Bob',0,false);
是否可以以某种方式更改playerOne的构造函数信息?例如,假设我想将“Bob”更改为“Alice”,但不创建新对象。这可能吗?
最佳答案
构造函数完成后,它只是一个普通的对象,可以正常读取和赋值属性。
playerOne.playerName = "Alice";
关于javascript - 是否可以在定义对象构造函数值后更改它们?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58381315/