O'Reilly logo

Eloquent JavaScript by Marijn Haverbeke

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Shape of a Module

Since the language does not prescribe a way to write modules, we will have to come up some techniques of our own. For modules that consist of only a few functions or objects (or just one), there’s not much to think about—you just write those functions or objects as usual and call it a module.

For bigger modules or modules that contain some “internal” elements—variables that are used by the module’s code but not part of its interface—there are reasons to do things differently.

In JavaScript, “top-level” variables all live together in a single space. When a lot of code is loaded into an environment, it becomes hard to keep track of which variable names are used, which makes it very easy to accidentally use a name that was already ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required