【发布时间】:2021-10-21 09:30:18
【问题描述】:
这是我的课:
class Player {
static list = new Map()
constructor(id) {
Player.list.set(id, this)
this.id = id;
this.x = 0;
this.y = 0;
...
}
}
如何循环每个玩家?谢谢解答
【问题讨论】:
-
你为什么在这里使用
Map?您只为每个实例设置一个 id。 -
你试过
for (const player of Player.list) {...}吗?这似乎应该基于developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
标签: javascript list class constructor