I’m creating a JavaScript game, previously I’ve always created the whole game inside a single JavaScript file. I’d like to be able to reduce coupling by separating the code into modules. Is it possible to write JavaScript in one file that is accessible from another file, using some kind of include statement?
<script type="text/javascript" src="assets/scripts/asset_manager.js"></script>
<script type="text/javascript" src="assets/scripts/game.js"></script>
I’d like for the javascript files to act in a similar fashion to Javas classes, e.g. within the game.js file writing something like this.extends('asset_manager').
Edit:
It looks like RequireJS and CommonJS are both good candidates, have you found any drawbacks or advantages of using either?
If you want some modularity, you could simple module pattern, or some helper lib like RequireJS or other implementation of CommonJS modules.