首页 > 解决方案 > 如何选择所有 javascripts 对象?

问题描述

这是我的课:

class Player {
  static list = new Map()
  constructor(id) {
    Player.list.set(id, this)
    this.id = id;
    this.x = 0;
    this.y = 0;
    ...
  }
}

我怎样才能循环每个玩家?感谢您的回答

标签: javascriptlistclassconstructor

解决方案


由于您使用的是要循环的地图,因此您可以使用以下示例:

Player.list.forEach(player => {
    players.update();
    players.getUpdatePack();
})

推荐阅读