Chapter 3. Modular JavaScript
This chapter covers
- The definition of modules
- Reasons to use modules in your SPA
- A review of JavaScript scope and object creation
- An analysis of a module’s syntax and mechanics
- An introduction to module loading and AMD modules
JavaScript is a powerful yet extremely flexible language that has become the de facto standard for adding interactivity to web applications. Even large companies such as Amazon.com, Google, and Walmart rely on it. It’s remarkably easy to learn and even easier to add working code to a web page. So it’s no wonder that the freedom it offers and its ease of use have contributed to its popularity.
The friendliness of the language is a double-edged sword, though. In any language as dynamic as JavaScript, it can be easy to find yourself with a chaotic code base if you’re not careful. In a presentation for Google Tech Talks, renowned developer, architect, author, and speaker Douglas Crockford stated that JavaScript has “some of the best ideas ever put into a programming language” (see http://googlecode.blogspot.com/2009/03/doug-crockford-javascript-good-parts.html). He added, however, that it also has “some of the worst ideas ever put into a programming language.”