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 ...
Get Eloquent JavaScript 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.