JSFiddle - React, Tailwind, and code Playground
by joplomacedo
JavaScript
class LeagueGamesHandler {
constructor( instance ) {
this.instance = instance;
}
static games = [];
create( game_obj ) {
const game = new Game(this.instance, game_obj);
LeagueGamesHandler.games[game_obj.id] = game;
return game;
}
get( game_id ) {
return LeagueGamesHandler.games[game_id];
}
}
class Game {
constructor( instance, game ) {
this.instance = instance;
this.game = game;
}
printDesc() {
console.log('instance: ', this.instance);
console.log('game: ', this.game.desc);
}
}
GamesHandler = new LeagueGamesHandler('the_main_instance');
game = GamesHandler.create({
id: '879ahsd',
desc: 'description'
});
GamesHandler.get('879ahsd').printDesc();