Organizing your codebase
Most programming platforms provide several mechanisms for structuring your code. Consider C#/.NET or Java: you can use classes, namespaces or packages, and compilation units (assemblies or JAR/WAR files). Notice the range from small-scale organizational units (classes) to large-scale ones (assemblies). This allows you to make a codebase more approachable by providing order at each level of detail.
Classic browser-based JavaScript development was quite unstructured. Functions were the only built-in language feature for organizing your code. You could split your code into separate script files, but these all share the same global context within a web page.
Over time, people have developed ways of organizing JavaScript code. The standard approach now is to use modules. There are a few different module systems available for JavaScript, but they all work in a similar way. Each module system includes the following aspects:
- A way of declaring a module with a name and its...