The way you do this is as follows:
var game_state = { active_enemies: [] }; function Enemy() {
Cm:
Notta bene: There are several problems with this appeal to the game state. Make sure that you are consistent (i.e. do not have enemies removing themselves from the list of active enemies, but heroes remove enemies from the map). This will also complicate the situation as the code becomes more complex (your enemy is not only an enemy in the game, but also a map state manager, but he is probably not the only map state manager. When you want to make changes to how you manage the state of the map, you want to make sure that the code is structured in such a way that you only need to change it in one place [preferred]).
source share