liveBook · Manning

Chapter 11: Chapter 11. Code modularization techniques

What you will learn in chapter 11 of Secrets of the JavaScript Ninja, Second Edition

The introduction explains why growing JavaScript applications benefit from modules and why developers used modularization techniques before ES6 introduced native modules.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction explains why growing JavaScript applications benefit from modules and why developers used modularization techniques before ES6 introduced native modules.

Key terms: modules, loosely coupled, consistent abstractions, encapsulate implementation details, global variables, mainline code, naming clashes, third-party code, pre-ES6, objects

11.1 Modularizing code in pre-ES6 JavaScript

The section explains why pre-ES6 JavaScript needs modularization techniques and the minimum capabilities a module system must provide.

Key terms: global scope, function scope, namespace, module, interface, module internals

11.1 Do you know?

This section poses three self-check questions about pre-ES6 modules, AMD and CommonJS, and ES6 module statements without explaining the answers.

11.1.1 Using objects, closures, and immediate functions to specify modules

This section explains how the pre-ES6 module pattern uses immediate functions, objects, and closures to hide implementation details and expose an interface, then shows how to extend modules and where the pattern falls short.

Key terms: scope, closure, numClicks, global namespace, module pattern, immediate function, public interface, closures, MouseCounterModule, augmenting modules

11.1.2 Modularizing JavaScript applications with AMD and CommonJS

The section explains how AMD and CommonJS define modules, expose interfaces, and load dependencies, then compares their suitability for browsers and servers.

Key terms: AMD, define, module ID, dependencies, factory function, public interface, CommonJS, file-based modules, module scope, module.exports

11.2 ES6 modules

This section introduces ES6 modules’ influences, their explicit boundary between internal and accessible identifiers, and the tooling needed to use them in the browser context described.

Key terms: ES6 modules, identifiers, top-level scope, export, import, CommonJS, AMD, file based, asynchronous module loading, transpile

11.2.1 Exporting and importing functionality

This section explains how ES6 modules keep unexported code private and how to export, import, and rename module functionality.

Key terms: module variable, top-level, export, named export, export keyword, import keyword, import *, named exports, property notation, default export

11.3 Summary

11.4 Exercises

Concepts explained in this chapter

← Chapter 10: Chapter 10. Wrangling regular expressions Chapter 12: Chapter 12. Working the DOM →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.