8
8
"stabilityText": "Locked",
9
"desc": "<p>Node has a simple module loading system. In Node, files and modules are in\none-to-one correspondence. As an example, <code>foo.js</code> loads the module\n<code>circle.js</code> in the same directory.\n\n</p>\n<p>The contents of <code>foo.js</code>:\n\n</p>\n<pre><code>var circle = require('./circle.js');\nconsole.log( 'The area of a circle of radius 4 is '\n + circle.area(4));</code></pre>\n<p>The contents of <code>circle.js</code>:\n\n</p>\n<pre><code>var PI = Math.PI;\n\nexports.area = function (r) {\n return PI * r * r;\n};\n\nexports.circumference = function (r) {\n return 2 * PI * r;\n};</code></pre>\n<p>The module <code>circle.js</code> has exported the functions <code>area()</code> and\n<code>circumference()</code>. To export an object, add to the special <code>exports</code>\nobject.\n\n</p>\n<p>Note that <code>exports</code> is a reference to <code>module.exports</code> making it suitable\nfor augmentation only. If you are exporting a single item such as a\nconstructor you will want to use <code>module.exports</code> directly instead.\n\n</p>\n<pre><code>function MyConstructor (opts) {\n //...\n}\n\n// BROKEN: Does not modify exports\nexports = MyConstructor;\n\n// exports the constructor properly\nmodule.exports = MyConstructor;</code></pre>\n<p>Variables\nlocal to the module will be private. In this example the variable <code>PI</code> is\nprivate to <code>circle.js</code>.\n\n</p>\n<p>The module system is implemented in the <code>require("module")</code> module.\n\n</p>\n",
9
"desc": "<p>Node has a simple module loading system. In Node, files and modules are in\none-to-one correspondence. As an example, <code>foo.js</code> loads the module\n<code>circle.js</code> in the same directory.\n\n</p>\n<p>The contents of <code>foo.js</code>:\n\n</p>\n<pre><code>var circle = require('./circle.js');\nconsole.log( 'The area of a circle of radius 4 is '\n + circle.area(4));</code></pre>\n<p>The contents of <code>circle.js</code>:\n\n</p>\n<pre><code>var PI = Math.PI;\n\nexports.area = function (r) {\n return PI * r * r;\n};\n\nexports.circumference = function (r) {\n return 2 * PI * r;\n};</code></pre>\n<p>The module <code>circle.js</code> has exported the functions <code>area()</code> and\n<code>circumference()</code>. To add functions and objects to the root of your module,\nyou can add them to the special <code>exports</code> object.\n\n</p>\n<p>Variables local to the module will be private, as though the module was wrapped\nin a function. In this example the variable <code>PI</code> is private to <code>circle.js</code>.\n\n</p>\n<p>If you want the root of your module's export to be a function (such as a\nconstructor) or if you want to export a complete object in one assignment\ninstead of building it one property at a time, assign it to <code>module.exports</code>\ninstead of <code>exports</code>.\n\n</p>\n<p>Below, <code>bar.js</code> makes use of the <code>square</code> module, which exports a constructor:\n\n</p>\n<pre><code>var square = require('./square.js');\nvar mySquare = square(2);\nconsole.log('The area of my square is ' + mySquare.area());</code></pre>\n<p>The <code>square</code> module is defined in <code>square.js</code>:\n\n</p>\n<pre><code>// assigning to exports will not modify module, must use module.exports\nmodule.exports = function(width) {\n return {\n area: function() {\n return width * width;\n }\n };\n}</code></pre>\n<p>The module system is implemented in the <code>require("module")</code> module.\n\n</p>\n",
12
12
"textRaw": "Cycles",
82
82
"textRaw": "The `module` Object",
85
"desc": "<p>In each module, the <code>module</code> free variable is a reference to the object\nrepresenting the current module. In particular\n<code>module.exports</code> is accessible via the <code>exports</code> module-global.\n<code>module</code> isn't actually a global but rather local to each module.\n\n</p>\n",
85
"desc": "<p>In each module, the <code>module</code> free variable is a reference to the object\nrepresenting the current module. For convenience, <code>module.exports</code> is\nalso accessible via the <code>exports</code> module-global. <code>module</code> isn't actually\na global but rather local to each module.\n\n</p>\n",
88
88
"textRaw": "`exports` {Object} ",
90
"desc": "<p>The <code>module.exports</code> object is created by the Module system. Sometimes this is not\nacceptable, many want their module to be an instance of some class. To do this\nassign the desired export object to <code>module.exports</code>. For example suppose we\nwere making a module called <code>a.js</code>\n\n</p>\n<pre><code>var EventEmitter = require('events').EventEmitter;\n\nmodule.exports = new EventEmitter();\n\n// Do some work, and after some time emit\n// the 'ready' event from the module itself.\nsetTimeout(function() {\n module.exports.emit('ready');\n}, 1000);</code></pre>\n<p>Then in another file we could do\n\n</p>\n<pre><code>var a = require('./a');\na.on('ready', function() {\n console.log('module a is ready');\n});</code></pre>\n<p>Note that assignment to <code>module.exports</code> must be done immediately. It cannot be\ndone in any callbacks. This does not work:\n\n</p>\n<p>x.js:\n\n</p>\n<pre><code>setTimeout(function() {\n module.exports = { a: "hello" };\n}, 0);</code></pre>\n<p>y.js:\n\n</p>\n<pre><code>var x = require('./x');\nconsole.log(x.a);</code></pre>\n"
90
"desc": "<p>The <code>module.exports</code> object is created by the Module system. Sometimes this is not\nacceptable; many want their module to be an instance of some class. To do this\nassign the desired export object to <code>module.exports</code>. Note that assigning the\ndesired object to <code>exports</code> will simply rebind the local <code>exports</code> variable,\nwhich is probably not what you want to do.\n\n</p>\n<p>For example suppose we were making a module called <code>a.js</code>\n\n</p>\n<pre><code>var EventEmitter = require('events').EventEmitter;\n\nmodule.exports = new EventEmitter();\n\n// Do some work, and after some time emit\n// the 'ready' event from the module itself.\nsetTimeout(function() {\n module.exports.emit('ready');\n}, 1000);</code></pre>\n<p>Then in another file we could do\n\n</p>\n<pre><code>var a = require('./a');\na.on('ready', function() {\n console.log('module a is ready');\n});</code></pre>\n<p>Note that assignment to <code>module.exports</code> must be done immediately. It cannot be\ndone in any callbacks. This does not work:\n\n</p>\n<p>x.js:\n\n</p>\n<pre><code>setTimeout(function() {\n module.exports = { a: "hello" };\n}, 0);</code></pre>\n<p>y.js:\n\n</p>\n<pre><code>var x = require('./x');\nconsole.log(x.a);</code></pre>\n",
93
"textRaw": "exports alias",
94
"name": "exports_alias",
95
"desc": "<p>The <code>exports</code> variable that is available within a module starts as a reference\nto <code>module.exports</code>. As with any variable, if you assign a new value to it, it\nis no longer bound to the previous value.\n\n</p>\n<p>To illustrate the behaviour, imagine this hypothetical implementation of\n<code>require()</code>:\n\n</p>\n<pre><code>function require(...) {\n // ...\n function (module, exports) {\n // Your module code here\n exports = some_func; // re-assigns exports, exports is no longer\n // a shortcut, and nothing is exported.\n module.exports = some_func; // makes your module export 0\n } (module, module.exports);\n return module;\n}</code></pre>\n<p>As a guideline, if the relationship between <code>exports</code> and <code>module.exports</code>\nseems like magic to you, ignore <code>exports</code> and only use <code>module.exports</code>.\n\n</p>\n",
97
"displayName": "exports alias"
93
102
"textRaw": "`id` {String} ",