I am writing a node.js application which I am breaking down into modules, the issue is I am not sure how to organise my code in an idiomatic Javascript way.
Currently each of my modules exposes a set of functions that are intended to be called directly. All state is modified by the module with the gameId being the first parameter :
//snip
var gameId = gameModule.createGame();
// Return the gameId down to a remote client
client.send(gameId);
}
// When a remote client wants to add a player
gameModule.addPlayer(gameId, "Player 1");
}
An alternative approach would be to actually use objects e.g. :
//snip
var game = new gameModule.Game();
// Return the gameId down to a remote client
client.send(game.getId());
}
//snip
// When a remote client wants to add a player
var gameToModify = gameModule.getGame(gameId);
gameToModify.addPlayer("Player 1");
gameModule.saveGame(gameToModify);
My question is to any Javascript programmers (or regular ones) is which of the two above alternatives looks easiest to work with / most natural?