Modular Design Patterns in JavaScript
Last week we've discussed how to create classes and namespaces in JavaScript. For those who missed it, you can read it here . There is however something else you need to know regarding the topic, which is modules. Modules When we say an application is modular, we generally mean it's composed of a set of highly decoupled, distinct pieces of functionality stored in modules. Module can and are implemented using classes, which we already know how to define. So what is the problem? When you try to build a complex piece of software, you end up with hundreds of classes. All of them somehow interact with one another and since JavaScript is not compiled, your job is to reference and load these classes in a correct order. This is why module loaders specification was invented - the most prominent of which are CommonJS and AMD . CommonJS Currently, CommonJS is a de facto standard. Many third-party vendors are making modules or module-load systems according to the CommonJS...