Skip to content

Commit e972add

Browse files
committed
Update module loading docs
1 parent b7526eb commit e972add

4 files changed

Lines changed: 19 additions & 5 deletions

File tree

doc/api.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ <h3 id="_modules">Modules</h3><div style="clear:left"></div>
472472
<div class="listingblock">
473473
<div class="content">
474474
<pre><tt>var circle = require("circle.js");
475+
include("/utils.js");
475476
puts("The area of a circle of radius 4 is " + circle.area(4));</tt></pre>
476477
</div></div>
477478
<div class="paragraph"><p>The contents of <tt>circle.js</tt>:</p></div>
@@ -491,7 +492,9 @@ <h3 id="_modules">Modules</h3><div style="clear:left"></div>
491492
<tt>circumference()</tt>. To export an object, add to the special <tt>exports</tt>
492493
object. (Alternatively, one can use <tt>this</tt> instead of <tt>exports</tt>.) Variables
493494
local to the module will be private. In this example the variable <tt>PI</tt> is
494-
private to <tt>circle.js</tt>.</p></div>
495+
private to <tt>circle.js</tt>. The function <tt>puts()</tt> comes from the module
496+
<tt>"/utils.js"</tt>. Because <tt>include("/utils.js")</tt> was called, <tt>puts()</tt> is in the
497+
global namespace.</p></div>
495498
<div class="paragraph"><p>The module path is relative to the file calling <tt>require()</tt>. That is,
496499
<tt>circle.js</tt> must be in the same directory as <tt>foo.js</tt> for <tt>require()</tt> to
497500
find it.</p></div>
@@ -501,6 +504,7 @@ <h3 id="_modules">Modules</h3><div style="clear:left"></div>
501504
<div class="listingblock">
502505
<div class="content">
503506
<pre><tt>include("circle.js");
507+
include("/utils.js");
504508
puts("The area of a cirlce of radius 4 is " + area(4));</tt></pre>
505509
</div></div>
506510
<div class="paragraph"><p>When an absolute path is given to <tt>require()</tt> or <tt>include()</tt>, like
@@ -2002,7 +2006,7 @@ <h2 id="_extension_api">Extension API</h2>
20022006
<div id="footer">
20032007
<div id="footer-text">
20042008
Version 0.1.12<br />
2005-
Last updated 2009-09-28 18:02:27 CEST
2009+
Last updated 2009-09-28 19:43:15 CEST
20062010
</div>
20072011
</div>
20082012
</body>

doc/api.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ The contents of +foo.js+:
265265

266266
----------------------------------------
267267
var circle = require("circle.js");
268+
include("/utils.js");
268269
puts("The area of a circle of radius 4 is " + circle.area(4));
269270
----------------------------------------
270271

@@ -286,7 +287,9 @@ The module +circle.js+ has exported the functions +area()+ and
286287
+circumference()+. To export an object, add to the special +exports+
287288
object. (Alternatively, one can use +this+ instead of +exports+.) Variables
288289
local to the module will be private. In this example the variable +PI+ is
289-
private to +circle.js+.
290+
private to +circle.js+. The function +puts()+ comes from the module
291+
+"/utils.js"+. Because +include("/utils.js")+ was called, +puts()+ is in the
292+
global namespace.
290293

291294
The module path is relative to the file calling +require()+. That is,
292295
+circle.js+ must be in the same directory as +foo.js+ for +require()+ to
@@ -298,6 +301,7 @@ the global namespace. For example:
298301

299302
----------------------------------------
300303
include("circle.js");
304+
include("/utils.js");
301305
puts("The area of a cirlce of radius 4 is " + area(4));
302306
----------------------------------------
303307

doc/api.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ one-to-one correspondence. As an example, <literal>foo.js</literal> loads the m
499499
<literal>circle.js</literal>.</simpara>
500500
<simpara>The contents of <literal>foo.js</literal>:</simpara>
501501
<screen>var circle = require("circle.js");
502+
include("/utils.js");
502503
puts("The area of a circle of radius 4 is " + circle.area(4));</screen>
503504
<simpara>The contents of <literal>circle.js</literal>:</simpara>
504505
<screen>var PI = 3.14;
@@ -514,14 +515,17 @@ exports.circumference = function (r) {
514515
<literal>circumference()</literal>. To export an object, add to the special <literal>exports</literal>
515516
object. (Alternatively, one can use <literal>this</literal> instead of <literal>exports</literal>.) Variables
516517
local to the module will be private. In this example the variable <literal>PI</literal> is
517-
private to <literal>circle.js</literal>.</simpara>
518+
private to <literal>circle.js</literal>. The function <literal>puts()</literal> comes from the module
519+
<literal>"/utils.js"</literal>. Because <literal>include("/utils.js")</literal> was called, <literal>puts()</literal> is in the
520+
global namespace.</simpara>
518521
<simpara>The module path is relative to the file calling <literal>require()</literal>. That is,
519522
<literal>circle.js</literal> must be in the same directory as <literal>foo.js</literal> for <literal>require()</literal> to
520523
find it.</simpara>
521524
<simpara>Like <literal>require()</literal> the function <literal>include()</literal> also loads a module. Instead of
522525
returning a namespace object, <literal>include()</literal> will add the module&#8217;s exports into
523526
the global namespace. For example:</simpara>
524527
<screen>include("circle.js");
528+
include("/utils.js");
525529
puts("The area of a cirlce of radius 4 is " + area(4));</screen>
526530
<simpara>When an absolute path is given to <literal>require()</literal> or <literal>include()</literal>, like
527531
<literal>require("/mjsunit.js")</literal> the module is searched for in the

doc/node.1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ The contents of foo\.js:
397397
.RS 4
398398
.nf
399399
var circle = require("circle\.js");
400+
include("/utils\.js");
400401
puts("The area of a circle of radius 4 is " + circle\.area(4));
401402
.fi
402403
.RE
@@ -416,7 +417,7 @@ exports\.circumference = function (r) {
416417
};
417418
.fi
418419
.RE
419-
The module circle\.js has exported the functions area() and circumference()\. To export an object, add to the special exports object\. (Alternatively, one can use this instead of exports\.) Variables local to the module will be private\. In this example the variable PI is private to circle\.js\.
420+
The module circle\.js has exported the functions area() and circumference()\. To export an object, add to the special exports object\. (Alternatively, one can use this instead of exports\.) Variables local to the module will be private\. In this example the variable PI is private to circle\.js\. The function puts() comes from the module "/utils\.js"\. Because include("/utils\.js") was called, puts() is in the global namespace\.
420421
.sp
421422
The module path is relative to the file calling require()\. That is, circle\.js must be in the same directory as foo\.js for require() to find it\.
422423
.sp
@@ -426,6 +427,7 @@ Like require() the function include() also loads a module\. Instead of returning
426427
.RS 4
427428
.nf
428429
include("circle\.js");
430+
include("/utils\.js");
429431
puts("The area of a cirlce of radius 4 is " + area(4));
430432
.fi
431433
.RE

0 commit comments

Comments
 (0)