|
@ -61,8 +61,8 @@ The module system is implemented in the `require("module")` module. |
|
|
|
|
|
|
|
|
<!--type=misc--> |
|
|
<!--type=misc--> |
|
|
|
|
|
|
|
|
When there are circular `require()` calls, a module might not be |
|
|
When there are circular `require()` calls, a module might not have finished |
|
|
done being executed when it is returned. |
|
|
executing when it is returned. |
|
|
|
|
|
|
|
|
Consider this situation: |
|
|
Consider this situation: |
|
|
|
|
|
|
|
@ -93,7 +93,7 @@ Consider this situation: |
|
|
|
|
|
|
|
|
When `main.js` loads `a.js`, then `a.js` in turn loads `b.js`. At that |
|
|
When `main.js` loads `a.js`, then `a.js` in turn loads `b.js`. At that |
|
|
point, `b.js` tries to load `a.js`. In order to prevent an infinite |
|
|
point, `b.js` tries to load `a.js`. In order to prevent an infinite |
|
|
loop an **unfinished copy** of the `a.js` exports object is returned to the |
|
|
loop, an **unfinished copy** of the `a.js` exports object is returned to the |
|
|
`b.js` module. `b.js` then finishes loading, and its `exports` object is |
|
|
`b.js` module. `b.js` then finishes loading, and its `exports` object is |
|
|
provided to the `a.js` module. |
|
|
provided to the `a.js` module. |
|
|
|
|
|
|
|
@ -248,7 +248,7 @@ a global but rather local to each module. |
|
|
* {Object} |
|
|
* {Object} |
|
|
|
|
|
|
|
|
The `module.exports` object is created by the Module system. Sometimes this is not |
|
|
The `module.exports` object is created by the Module system. Sometimes this is not |
|
|
acceptable; many want their module to be an instance of some class. To do this |
|
|
acceptable; many want their module to be an instance of some class. To do this, |
|
|
assign the desired export object to `module.exports`. Note that assigning the |
|
|
assign the desired export object to `module.exports`. Note that assigning the |
|
|
desired object to `exports` will simply rebind the local `exports` variable, |
|
|
desired object to `exports` will simply rebind the local `exports` variable, |
|
|
which is probably not what you want to do. |
|
|
which is probably not what you want to do. |
|
|