summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorRyan Graham <r.m.graham@gmail.com>2013-04-08 09:59:15 -0700
committerBen Noordhuis <info@bnoordhuis.nl>2013-05-15 21:05:57 +0200
commit93391ae9cb162dc79d3307b0e7767f5f505a5c69 (patch)
treeb3b41de544998d5cdce9a80e0d18fc35a8be7f02 /doc
parent6bcf51e0302a587c6494feb3a6792fe7d2b1eea4 (diff)
downloadnode-93391ae9cb162dc79d3307b0e7767f5f505a5c69.tar.gz
doc: clarify exports and module.exports
When exporting a single function you must use `module.exports` instead of the `exports` convenience reference.
Diffstat (limited to 'doc')
-rw-r--r--doc/api/globals.markdown7
-rw-r--r--doc/api/modules.markdown16
2 files changed, 19 insertions, 4 deletions
diff --git a/doc/api/globals.markdown b/doc/api/globals.markdown
index bc2996b71..2f797be3e 100644
--- a/doc/api/globals.markdown
+++ b/doc/api/globals.markdown
@@ -133,9 +133,10 @@ See the [module system documentation][] for more information.
<!-- type=var -->
-An object which is shared between all instances of the current module and
-made accessible through `require()`.
-`exports` is the same as the `module.exports` object.
+A reference to the `module.exports` object which is shared between all
+instances of the current module and made accessible through `require()`.
+See [module system documentation][] for details on when to use `exports` and
+when to use `module.exports`.
`exports` isn't actually a global but rather local to each module.
See the [module system documentation][] for more information.
diff --git a/doc/api/modules.markdown b/doc/api/modules.markdown
index 4720aa5ec..95e301265 100644
--- a/doc/api/modules.markdown
+++ b/doc/api/modules.markdown
@@ -30,6 +30,20 @@ The module `circle.js` has exported the functions `area()` and
`circumference()`. To export an object, add to the special `exports`
object.
+Note that `exports` is a reference to `module.exports` making it suitable
+for augmentation only. If you are exporting a single item such as a
+constructor you will want to use `module.exports` directly instead.
+
+ function MyConstructor (opts) {
+ //...
+ }
+
+ // BROKEN: Does not modify exports
+ exports = MyConstructor;
+
+ // exports the constructor properly
+ module.exports = MyConstructor;
+
Variables
local to the module will be private. In this example the variable `PI` is
private to `circle.js`.
@@ -219,7 +233,7 @@ would resolve to different files.
In each module, the `module` free variable is a reference to the object
representing the current module. In particular
-`module.exports` is the same as the `exports` object.
+`module.exports` is accessible via the `exports` module-global.
`module` isn't actually a global but rather local to each module.
### module.exports