samedi 23 janvier 2021

how to fix object cyclic dependency in javascript

I have a class Game has a property guiGame which is an instance of GuiGame

const Game = function() {this.guiGame = new GuiGame(this) ...}

the GuiGame class also has a property 'game'

const GuiGame = function (game){
     this.game = game
}
GuiGame.prototype.onClick = function() {this.game.start()}

How can I fix object cyclic dependency for Game and GuiGame?

Aucun commentaire:

Enregistrer un commentaire