Skip to Content
Programming JavaScript Applications
book

Programming JavaScript Applications

by Eric Elliott
June 2014
Intermediate to advanced
254 pages
6h 2m
English
O'Reilly Media, Inc.
Content preview from Programming JavaScript Applications

Chapter 4. Modules

Modules are reusable software components that form the building blocks of applications. Modularity satisfies some very important design goals, perhaps the most important of which is simplicity.

When you design an application with a lot of interdependencies between different parts, it becomes more difficult to fully understand the impact of your changes across the whole system.

If you design parts of a system to a modular interface contract instead, you can safely make changes without having a deep understanding of all of the related modules.

Another important goal of modularity is the ability to reuse your module in other applications. Well-designed modules built on similar frameworks should be easy to transplant into new applications with few (if any) changes. By defining a standard interface for application extensions and then building your functionality on top of that interface, you’ll go a long way toward building an application that is easy to extend and maintain and easy to reassemble into different forms in the future.

JavaScript modules are encapsulated, meaning that they keep implementation details private and expose a public API. That way, you can change how a module behaves under the hood without changing code that relies on it. Encapsulation also provides protection, meaning that it prevents outside code from interfering with the functionality of the module.

There are several ways to define modules in JavaScript. The most popular and common are the module ...

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.
Start your free trial

You might also like

JavaScript : Object-Oriented Programming

JavaScript : Object-Oriented Programming

Kumar Chetan Sharma et al
Testing JavaScript Applications

Testing JavaScript Applications

Lucas Fernandes da Costa

Publisher Resources

ISBN: 9781491950289Errata PageSupplemental Content