Browse Source

Update module loading docs

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
e972add0ea
  1. 8
      doc/api.html
  2. 6
      doc/api.txt
  3. 6
      doc/api.xml
  4. 4
      doc/node.1

8
doc/api.html

@ -472,6 +472,7 @@ one-to-one correspondence. As an example, <tt>foo.js</tt> loads the module
<div class="listingblock">
<div class="content">
<pre><tt>var circle = require("circle.js");
include("/utils.js");
puts("The area of a circle of radius 4 is " + circle.area(4));</tt></pre>
</div></div>
<div class="paragraph"><p>The contents of <tt>circle.js</tt>:</p></div>
@ -491,7 +492,9 @@ exports.circumference = function (r) {
<tt>circumference()</tt>. To export an object, add to the special <tt>exports</tt>
object. (Alternatively, one can use <tt>this</tt> instead of <tt>exports</tt>.) Variables
local to the module will be private. In this example the variable <tt>PI</tt> is
private to <tt>circle.js</tt>.</p></div>
private to <tt>circle.js</tt>. The function <tt>puts()</tt> comes from the module
<tt>"/utils.js"</tt>. Because <tt>include("/utils.js")</tt> was called, <tt>puts()</tt> is in the
global namespace.</p></div>
<div class="paragraph"><p>The module path is relative to the file calling <tt>require()</tt>. That is,
<tt>circle.js</tt> must be in the same directory as <tt>foo.js</tt> for <tt>require()</tt> to
find it.</p></div>
@ -501,6 +504,7 @@ the global namespace. For example:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>include("circle.js");
include("/utils.js");
puts("The area of a cirlce of radius 4 is " + area(4));</tt></pre>
</div></div>
<div class="paragraph"><p>When an absolute path is given to <tt>require()</tt> or <tt>include()</tt>, like
@ -2002,7 +2006,7 @@ init (Handle&lt;Object&gt; target)
<div id="footer">
<div id="footer-text">
Version 0.1.12<br />
Last updated 2009-09-28 18:02:27 CEST
Last updated 2009-09-28 19:43:15 CEST
</div>
</div>
</body>

6
doc/api.txt

@ -265,6 +265,7 @@ The contents of +foo.js+:
----------------------------------------
var circle = require("circle.js");
include("/utils.js");
puts("The area of a circle of radius 4 is " + circle.area(4));
----------------------------------------
@ -286,7 +287,9 @@ 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+.
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.
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
@ -298,6 +301,7 @@ the global namespace. For example:
----------------------------------------
include("circle.js");
include("/utils.js");
puts("The area of a cirlce of radius 4 is " + area(4));
----------------------------------------

6
doc/api.xml

@ -499,6 +499,7 @@ one-to-one correspondence. As an example, <literal>foo.js</literal> loads the m
<literal>circle.js</literal>.</simpara>
<simpara>The contents of <literal>foo.js</literal>:</simpara>
<screen>var circle = require("circle.js");
include("/utils.js");
puts("The area of a circle of radius 4 is " + circle.area(4));</screen>
<simpara>The contents of <literal>circle.js</literal>:</simpara>
<screen>var PI = 3.14;
@ -514,7 +515,9 @@ exports.circumference = function (r) {
<literal>circumference()</literal>. To export an object, add to the special <literal>exports</literal>
object. (Alternatively, one can use <literal>this</literal> instead of <literal>exports</literal>.) Variables
local to the module will be private. In this example the variable <literal>PI</literal> is
private to <literal>circle.js</literal>.</simpara>
private to <literal>circle.js</literal>. The function <literal>puts()</literal> comes from the module
<literal>"/utils.js"</literal>. Because <literal>include("/utils.js")</literal> was called, <literal>puts()</literal> is in the
global namespace.</simpara>
<simpara>The module path is relative to the file calling <literal>require()</literal>. That is,
<literal>circle.js</literal> must be in the same directory as <literal>foo.js</literal> for <literal>require()</literal> to
find it.</simpara>
@ -522,6 +525,7 @@ find it.</simpara>
returning a namespace object, <literal>include()</literal> will add the module&#8217;s exports into
the global namespace. For example:</simpara>
<screen>include("circle.js");
include("/utils.js");
puts("The area of a cirlce of radius 4 is " + area(4));</screen>
<simpara>When an absolute path is given to <literal>require()</literal> or <literal>include()</literal>, like
<literal>require("/mjsunit.js")</literal> the module is searched for in the

4
doc/node.1

@ -397,6 +397,7 @@ The contents of foo\.js:
.RS 4
.nf
var circle = require("circle\.js");
include("/utils\.js");
puts("The area of a circle of radius 4 is " + circle\.area(4));
.fi
.RE
@ -416,7 +417,7 @@ exports\.circumference = function (r) {
};
.fi
.RE
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 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\.
.sp
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\.
.sp
@ -426,6 +427,7 @@ Like require() the function include() also loads a module\. Instead of returning
.RS 4
.nf
include("circle\.js");
include("/utils\.js");
puts("The area of a cirlce of radius 4 is " + area(4));
.fi
.RE

Loading…
Cancel
Save