How to get out of a mess using modular JavaScript
How many digital photos do you have, probably thousands, or more? Just imagine if your image viewer had no capacity to categorize. No albums, no books, no categories, nothing. It would not be of much use, does it? Now let's assume that you have a JavaScript application in a single file and it grows. When it approaches thousand or more than a thousand lines of code, however good your code design is, from a maintainability perspective, it still turns into a useless pile like that enormous list of uncategorized photos. Instead of building a monolithic application, we have to write several independent modules that combine together to form an application. Thus, we break a complex problem into simpler tasks.
Modules
So, what is a module? A module encapsulates code intended for a particular functionality. A module also provides an interface declaring what elements the module exposes and requires. A module is often packaged in a single file, which...