Summary

It has been said that there are only two really hard things in computing science. What those issues are varies depending on who is speaking. Frequently it is some variation of cache invalidation and naming. How to organize your code is a large part of that naming problem.

As a group we seem to have settled quite firmly on the idea of namespaces and classes. As we've seen, there is no direct support for either of these two concepts in JavaScript. However there are myriad ways to work around the problem, some of which actually provide more power than one would get through a traditional namespace/class system.

The primary concern with JavaScript is to avoid polluting the global namespace with a large number of similarly named, unconnected objects. ...

Get Mastering JavaScript Design Patterns - Second Edition 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.