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. ...

Get Mastering JavaScript Object-Oriented Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.