CommonJS (CJS) is a dynamic JavaScript module system built around programmatic loading and the require/module.exports convention. Dependencies and exposed APIs are resolved while the code runs, so require calls can appear where conditional behavior needs them. section 6.3 section 6.4.3
A CJS module can expose values and functions through exports, while internal variables and helper functions remain private. Consumers receive object values through require; destructuring creates local copies rather than live bindings. section 6.3 section 6.4.3
A configurable calculator module
A calculator module exports feePercent, netTotal, and setFeePercent while keeping precisionRound private. Reassigning a destructured feePercent does not change the module’s value; calling setFeePercent does. section 6.3
Conditional loading
Feature flags can select between compute_balance.js and compute_balance2.js by requiring one module initially and replacing the selected function when a flag is enabled. section 6.4.3
Table 6.1 Loading the Transaction class with different module systems (continued) (view table figure)
requirejs(['domain/Transaction.js'], Transaction => {
|
||
Compare CommonJS’s dynamic require call with RequireJS and ESM import syntax. section 6.3


