diff --git a/node.html b/node.html index 280ce04cc8..fc72e5ec9d 100644 --- a/node.html +++ b/node.html @@ -43,21 +43,21 @@ h1 a { color: inherit; } h2 { margin: 2em 0; - font-size: inherit; + font-size: 45px; line-height: inherit; font-weight: bold; } h3 { margin: 1em 0; - font-size: inherit; + font-size: 30px; line-height: inherit; font-weight: inherit; } pre, code { font-family: monospace; - font-size: 12pt; + font-size: 13pt; } dl { @@ -298,14 +298,22 @@ msg.onBody = function (chunk) { puts("part of the body: " + chunk); } - A piece of the body is given as the single argument. The transfer-encoding + A chunk of the body is given as the single argument. The transfer-encoding has been removed. +
The body chunk is either a String in the case of utf8 encoding or an + array of numbers in the case of raw encoding.
msg.onBodyComplete
onBodyComplete
is executed onBody
will no longer be called.
msg.setBodyEncoding(encoding)
"utf8"
or
+ "raw"
. Defaults to raw.
+ TODO
+
msg.sendHeader(status_code, headers)
Node has simple module loading. Here is an example of loading a module: +
+include("mjsunit"); + +function onLoad () { + assertEquals(1, 2); +} ++
Here the module mjsunit
has provided the function
+assertEquals()
.
+
+
The file mjsunit.js
must be in the same directory for this
+to work. The include()
function will take all the exported
+objects from the file and put them into the global namespace. Because file
+loading does not happen instantaniously, and because Node has a policy of
+never blocking, the callback onLoad()
is provided to notify the
+user when all the exported functions are completely loaded.
+
+
To export an object, add to the special object exports
.
+Let's look at how mjsunit.js
does this
+
+
+function fail (expected, found, name_opt) { + // ... +} + +function deepEquals (a, b) { + // ... +} + +exports.assertEquals = function (expected, found, name_opt) { + if (!deepEquals(found, expected)) { + fail(expected, found, name_opt); + } +}; ++
The functions fail
and deepEquals
are not
+exported and remain private to the module.
+
+
In addition to include()
a module can use
+require()
. Instead of loading the exported objects into the
+global namespace, it will return a namespace object. Again, the members of
+the namespace object can only be guarenteed to exist after the
+onLoad()
callback is made. For example:
+
+var mjsunit = require("mjsunit"); + +function onLoad () { + mjsunit.assertEquals(1, 2); +} ++ +