doc: improve exports/module.exports consistency
While they reference the same object, they are only interchangeable for updates, not assignment.
This commit is contained in:
parent
93391ae9cb
commit
1deeab29f2
@ -87,7 +87,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.
|
||||||
|
|
||||||
By the time `main.js` has loaded both modules, they're both finished.
|
By the time `main.js` has loaded both modules, they're both finished.
|
||||||
@ -240,7 +240,7 @@ representing the current module. In particular
|
|||||||
|
|
||||||
* {Object}
|
* {Object}
|
||||||
|
|
||||||
The `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`. For example suppose we
|
assign the desired export object to `module.exports`. For example suppose we
|
||||||
were making a module called `a.js`
|
were making a module called `a.js`
|
||||||
@ -281,13 +281,13 @@ y.js:
|
|||||||
### module.require(id)
|
### module.require(id)
|
||||||
|
|
||||||
* `id` {String}
|
* `id` {String}
|
||||||
* Return: {Object} `exports` from the resolved module
|
* Return: {Object} `module.exports` from the resolved module
|
||||||
|
|
||||||
The `module.require` method provides a way to load a module as if
|
The `module.require` method provides a way to load a module as if
|
||||||
`require()` was called from the original module.
|
`require()` was called from the original module.
|
||||||
|
|
||||||
Note that in order to do this, you must get a reference to the `module`
|
Note that in order to do this, you must get a reference to the `module`
|
||||||
object. Since `require()` returns the `exports`, and the `module` is
|
object. Since `require()` returns the `module.exports`, and the `module` is
|
||||||
typically *only* available within a specific module's code, it must be
|
typically *only* available within a specific module's code, it must be
|
||||||
explicitly exported in order to be used.
|
explicitly exported in order to be used.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user