Summary
In this chapter, we discussed some ways to organize the code of a complex JavaScript application. We started by analyzing the global scope as a repository of shared data and agreed how it is better to minimize its use and to find a way to avoid name collisions. So, we introduced the concept of namespace and implemented it as object literals and as IIFE.
Then, we started to discuss the concept of module as the basic organizational unit that many languages supports natively. The lack of this construct in JavaScript before ECMAScript 6 specification has given rise to several proposals. We explored the module pattern, the classic approach based on the closure of an IIFE, and analyzed the various approaches in augmenting and combining modules. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access