Skip to content

Commit f7356cb

Browse files
committed
Merge pull request visionmedia#18 from grantheaslip/master
Fixed some typos, cleaned up awkward/unclear sentences
2 parents 07033e6 + 15dc0e8 commit f7356cb

File tree

13 files changed

+144
-160
lines changed

13 files changed

+144
-160
lines changed

book.html

Lines changed: 48 additions & 50 deletions
Large diffs are not rendered by default.

chapters/buffers.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<div class='mp'>
22
<h1>Buffers</h1>
3-
<p> To handle binary data, node provides us with the global <code>Buffer</code> object. Buffer instances represent memory allocated independently to that of V8's heap. There are several ways to construct a <code>Buffer</code> instance, and many ways you can manipulate it's data.</p>
3+
<p> To handle binary data, node provides us with the global <code>Buffer</code> object. <code>Buffer</code> instances represent memory allocated independently of V8's heap. There are several ways to construct a <code>Buffer</code> instance, and many ways you can manipulate its data.</p>
44

5-
<p>The simplest way to construct a <code>Buffer</code> from a string is to simply pass a string as the first argument. As you can see by the log output, we now have a buffer object containing 5 bytes of data represented in hexadecimal.</p>
5+
<p>The simplest way to construct a <code>Buffer</code> from a string is to simply pass a string as the first argument. As you can see in the log output, we now have a buffer object containing 5 bytes of data represented in hexadecimal.</p>
66

77
<pre><code>var hello = new Buffer('Hello');
88

@@ -13,7 +13,7 @@ <h1>Buffers</h1>
1313
// =&gt; "Hello"
1414
</code></pre>
1515

16-
<p>By default the encoding is "utf8", however this can be specified by passing as string as the second argument. The ellipsis below for example will be printed to stdout as the '&amp;' character when in "ascii" encoding.</p>
16+
<p>By default, the encoding is "utf8", but this can be overridden by passing a string as the second argument. For example, the ellipsis below will be printed to stdout as the "&amp;" character when in "ascii" encoding.</p>
1717

1818
<pre><code>var buf = new Buffer('…');
1919
console.log(buf.toString());
@@ -24,12 +24,12 @@ <h1>Buffers</h1>
2424
// =&gt; &amp;
2525
</code></pre>
2626

27-
<p>An alternative method is to pass an array of integers representing the octet stream, however in this case functionality equivalent.</p>
27+
<p>An alternative (but in this case functionality equivalent) method is to pass an array of integers representing the octet stream.</p>
2828

2929
<pre><code>var hello = new Buffer([0x48, 0x65, 0x6c, 0x6c, 0x6f]);
3030
</code></pre>
3131

32-
<p>Buffers can also be created with an integer representing the number of bytes allocated, after which we may call the <code>write()</code> method, providing an optional offset and encoding. As shown below we provide the offset of 2 bytes to our second call to <code>write()</code>, buffering "Hel", and then we continue on to write another two bytes with an offset of 3, completing "Hello".</p>
32+
<p>Buffers can also be created with an integer representing the number of bytes allocated, after which we can call the <code>write()</code> method, providing an optional offset and encoding. Below, we provide an offset of 2 bytes to our second call to <code>write()</code> (buffering "Hel") and then write another two bytes with an offset of 3 (completing "Hello").</p>
3333

3434
<pre><code>var buf = new Buffer(5);
3535
buf.write('He');
@@ -39,7 +39,7 @@ <h1>Buffers</h1>
3939
// =&gt; "Hello"
4040
</code></pre>
4141

42-
<p>The <code>.length</code> property of a buffer instance contains the byte length of the stream, opposed to JavaScript strings which will simply return the number of characters. For example the ellipsis character '…' consists of three bytes, however the buffer will respond with the byte length, and not the character length.</p>
42+
<p>The <code>.length</code> property of a buffer instance contains the byte length of the stream, as opposed to native strings, which simply return the number of characters. For example, the ellipsis character '…' consists of three bytes, so the buffer will respond with the byte length (3), and not the character length (1).</p>
4343

4444
<pre><code>var ellipsis = new Buffer('…', 'utf8');
4545

@@ -53,16 +53,16 @@ <h1>Buffers</h1>
5353
// =&gt; &lt;Buffer e2 80 a6>
5454
</code></pre>
5555

56-
<p>When dealing with JavaScript strings, we may pass it to the <code>Buffer.byteLength()</code> method to determine it's byte length.</p>
56+
<p>To determine the byte length of a native string, pass it to the <code>Buffer.byteLength()</code> method.</p>
5757

58-
<p>The api is written in such a way that it is String-like, so for example we can work with "slices" of a <code>Buffer</code> by passing offsets to the <code>slice()</code> method:</p>
58+
<p>The API is written in such a way that it is String-like. For example, we can work with "slices" of a <code>Buffer</code> by passing offsets to the <code>slice()</code> method:</p>
5959

6060
<pre><code>var chunk = buf.slice(4, 9);
6161
console.log(chunk.toString());
6262
// =&gt; "some"
6363
</code></pre>
6464

65-
<p>Alternatively when expecting a string we can pass offsets to <code>Buffer#toString()</code>:</p>
65+
<p>Alternatively, when expecting a string, we can pass offsets to <code>Buffer#toString()</code>:</p>
6666

6767
<pre><code>var buf = new Buffer('just some data');
6868
console.log(buf.toString('ascii', 4, 9));

chapters/buffers.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
# Buffers
33

4-
To handle binary data, node provides us with the global `Buffer` object. Buffer instances represent memory allocated independently to that of V8's heap. There are several ways to construct a `Buffer` instance, and many ways you can manipulate it's data.
4+
To handle binary data, node provides us with the global `Buffer` object. `Buffer` instances represent memory allocated independently of V8's heap. There are several ways to construct a `Buffer` instance, and many ways you can manipulate its data.
55

6-
The simplest way to construct a `Buffer` from a string is to simply pass a string as the first argument. As you can see by the log output, we now have a buffer object containing 5 bytes of data represented in hexadecimal.
6+
The simplest way to construct a `Buffer` from a string is to simply pass a string as the first argument. As you can see in the log output, we now have a buffer object containing 5 bytes of data represented in hexadecimal.
77

88
var hello = new Buffer('Hello');
99

@@ -13,7 +13,7 @@ The simplest way to construct a `Buffer` from a string is to simply pass a strin
1313
console.log(hello.toString());
1414
// => "Hello"
1515

16-
By default the encoding is "utf8", however this can be specified by passing as string as the second argument. The ellipsis below for example will be printed to stdout as the '&' character when in "ascii" encoding.
16+
By default, the encoding is "utf8", but this can be overridden by passing a string as the second argument. For example, the ellipsis below will be printed to stdout as the "&" character when in "ascii" encoding.
1717

1818
var buf = new Buffer('…');
1919
console.log(buf.toString());
@@ -23,11 +23,11 @@ By default the encoding is "utf8", however this can be specified by passing as s
2323
console.log(buf.toString());
2424
// => &
2525

26-
An alternative method is to pass an array of integers representing the octet stream, however in this case functionality equivalent.
26+
An alternative (but in this case functionality equivalent) method is to pass an array of integers representing the octet stream.
2727

2828
var hello = new Buffer([0x48, 0x65, 0x6c, 0x6c, 0x6f]);
2929

30-
Buffers can also be created with an integer representing the number of bytes allocated, after which we may call the `write()` method, providing an optional offset and encoding. As shown below we provide the offset of 2 bytes to our second call to `write()`, buffering "Hel", and then we continue on to write another two bytes with an offset of 3, completing "Hello".
30+
Buffers can also be created with an integer representing the number of bytes allocated, after which we can call the `write()` method, providing an optional offset and encoding. Below, we provide an offset of 2 bytes to our second call to `write()` (buffering "Hel") and then write another two bytes with an offset of 3 (completing "Hello").
3131

3232
var buf = new Buffer(5);
3333
buf.write('He');
@@ -36,7 +36,7 @@ Buffers can also be created with an integer representing the number of bytes all
3636
console.log(buf.toString());
3737
// => "Hello"
3838

39-
The `.length` property of a buffer instance contains the byte length of the stream, opposed to JavaScript strings which will simply return the number of characters. For example the ellipsis character '…' consists of three bytes, however the buffer will respond with the byte length, and not the character length.
39+
The `.length` property of a buffer instance contains the byte length of the stream, as opposed to native strings, which simply return the number of characters. For example, the ellipsis character '…' consists of three bytes, so the buffer will respond with the byte length (3), and not the character length (1).
4040

4141
var ellipsis = new Buffer('…', 'utf8');
4242

@@ -49,17 +49,16 @@ The `.length` property of a buffer instance contains the byte length of the stre
4949
console.log(ellipsis);
5050
// => <Buffer e2 80 a6>
5151

52-
When dealing with JavaScript strings, we may pass it to the `Buffer.byteLength()` method to determine it's byte length.
52+
To determine the byte length of a native string, pass it to the `Buffer.byteLength()` method.
5353

54-
The api is written in such a way that it is String-like, so for example we can work with "slices" of a `Buffer` by passing offsets to the `slice()` method:
54+
The API is written in such a way that it is String-like. For example, we can work with "slices" of a `Buffer` by passing offsets to the `slice()` method:
5555

5656
var chunk = buf.slice(4, 9);
5757
console.log(chunk.toString());
5858
// => "some"
5959

60-
Alternatively when expecting a string we can pass offsets to `Buffer#toString()`:
60+
Alternatively, when expecting a string, we can pass offsets to `Buffer#toString()`:
6161

6262
var buf = new Buffer('just some data');
6363
console.log(buf.toString('ascii', 4, 9));
6464
// => "some"
65-

chapters/events.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<div class='mp'>
22
<h1>Events</h1>
3-
<p> The concept of an "event" is crucial to node, and used greatly throughout core and 3rd-party modules. Node's core module <em>events</em> supplies us with a single constructor, <em>EventEmitter</em>.</p>
3+
<p> The concept of an "event" is crucial to node, and is used heavily throughout core and 3rd-party modules. Node's core module <em>events</em> supplies us with a single constructor, <em>EventEmitter</em>.</p>
44

55
<h2 id="Emitting-Events">Emitting Events</h2>
66

7-
<p>Typically an object inherits from <em>EventEmitter</em>, however our small example below illustrates the api. First we create an <code>emitter</code>, after which we can define any number of callbacks using the <code>emitter.on()</code> method which accepts the <em>name</em> of the event, and arbitrary objects passed as data. When <code>emitter.emit()</code> is called we are only required to pass the event <em>name</em>, followed by any number of arguments, in this case the <code>first</code> and <code>last</code> name strings.</p>
7+
<p>Typically an object inherits from <em>EventEmitter</em>, however our small example below illustrates the API. First we create an <code>emitter</code>, after which we can define any number of callbacks using the <code>emitter.on()</code> method, which accepts the <em>name</em> of the event and arbitrary objects passed as data. When <code>emitter.emit()</code> is called, we are only required to pass the event <em>name</em>, followed by any number of arguments (in this case the <code>first</code> and <code>last</code> name strings).</p>
88

99
<pre><code>var EventEmitter = require('events').EventEmitter;
1010

@@ -20,9 +20,9 @@ <h2 id="Emitting-Events">Emitting Events</h2>
2020

2121
<h2 id="Inheriting-From-EventEmitter">Inheriting From EventEmitter</h2>
2222

23-
<p>A perhaps more practical use of <code>EventEmitter</code>, and commonly used throughout node is to inherit from it. This means we can leave <code>EventEmitter</code>'s prototype untouched, while utilizing its api for our own means of world domination!</p>
23+
<p>A more practical and common use of <code>EventEmitter</code> is to inherit from it. This means we can leave <code>EventEmitter</code>'s prototype untouched while utilizing its API for our own means of world domination!</p>
2424

25-
<p>To do so we begin by defining the <code>Dog</code> constructor, which of course will bark from time to time, also known as an <em>event</em>.</p>
25+
<p>To do so, we begin by defining the <code>Dog</code> constructor, which of course will bark from time to time (also known as an <em>event</em>).</p>
2626

2727
<pre><code>var EventEmitter = require('events').EventEmitter;
2828

@@ -31,12 +31,12 @@ <h2 id="Inheriting-From-EventEmitter">Inheriting From EventEmitter</h2>
3131
}
3232
</code></pre>
3333

34-
<p>Here we inherit from <code>EventEmitter</code>, so that we may use the methods provided such as <code>EventEmitter#on()</code> and <code>EventEmitter#emit()</code>. If the <code>__proto__</code> property is throwing you off, no worries! we will be touching on this later.</p>
34+
<p>Here we inherit from <code>EventEmitter</code> so we can use the methods it provides, such as <code>EventEmitter#on()</code> and <code>EventEmitter#emit()</code>. If the <code>__proto__</code> property is throwing you off, don't worry, we'll be coming back to this later.</p>
3535

3636
<pre><code>Dog.prototype.__proto__ = EventEmitter.prototype;
3737
</code></pre>
3838

39-
<p>Now that we have our <code>Dog</code> set up, we can create .... simon! When simon barks we can let <em>stdout</em> know by calling <code>console.log()</code> within the callback. The callback it-self is called in context to the object, aka <code>this</code>.</p>
39+
<p>Now that we have our <code>Dog</code> set up, we can create... Simon! When Simon barks, we can let <em>stdout</em> know by calling <code>console.log()</code> within the callback. The callback itself is called in the context of the object (aka <code>this</code>).</p>
4040

4141
<pre><code>var simon = new Dog('simon');
4242

@@ -45,7 +45,7 @@ <h2 id="Inheriting-From-EventEmitter">Inheriting From EventEmitter</h2>
4545
});
4646
</code></pre>
4747

48-
<p>Bark twice a second:</p>
48+
<p>Bark twice per second:</p>
4949

5050
<pre><code>setInterval(function(){
5151
simon.emit('bark');
@@ -54,7 +54,7 @@ <h2 id="Inheriting-From-EventEmitter">Inheriting From EventEmitter</h2>
5454

5555
<h2 id="Removing-Event-Listeners">Removing Event Listeners</h2>
5656

57-
<p>As we have seen event listeners are simply functions which are called when we <code>emit()</code> an event. Although not seen often we can remove these listeners by calling the <code>removeListener(type, callback)</code> method. In the example below we emit the <em>message</em> "foo bar" every <code>300</code> milliseconds, which has the callback of <code>console.log()</code>. After 1000 milliseconds we call <code>removeListener()</code> with the same arguments that we passed to <code>on()</code> originally. To compliment this method is <code>removeAllListeners(type)</code> which removes all listeners associated to the given <em>type</em>.</p>
57+
<p>As we have seen, event listeners are simply functions which are called when we <code>emit()</code> an event. We can remove these listeners by calling the <code>removeListener(type, callback)</code> method, although this isn't seen often. In the example below we emit the <em>message</em> "foo bar" every <code>300</code> milliseconds, which has a callback of <code>console.log()</code>. After 1000 milliseconds, we call <code>removeListener()</code> with the same arguments that we passed to <code>on()</code> originally. We could also have used <code>removeAllListeners(type)</code>, which removes all listeners registered to the given <em>type</em>.</p>
5858

5959
<pre><code>var EventEmitter = require('events').EventEmitter;
6060

chapters/events.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

22
# Events
33

4-
The concept of an "event" is crucial to node, and used greatly throughout core and 3rd-party modules. Node's core module _events_ supplies us with a single constructor, _EventEmitter_.
4+
The concept of an "event" is crucial to node, and is used heavily throughout core and 3rd-party modules. Node's core module _events_ supplies us with a single constructor, _EventEmitter_.
55

66
## Emitting Events
77

8-
Typically an object inherits from _EventEmitter_, however our small example below illustrates the api. First we create an `emitter`, after which we can define any number of callbacks using the `emitter.on()` method which accepts the _name_ of the event, and arbitrary objects passed as data. When `emitter.emit()` is called we are only required to pass the event _name_, followed by any number of arguments, in this case the `first` and `last` name strings.
8+
Typically an object inherits from _EventEmitter_, however our small example below illustrates the API. First we create an `emitter`, after which we can define any number of callbacks using the `emitter.on()` method, which accepts the _name_ of the event and arbitrary objects passed as data. When `emitter.emit()` is called, we are only required to pass the event _name_, followed by any number of arguments (in this case the `first` and `last` name strings).
99

1010
var EventEmitter = require('events').EventEmitter;
1111

@@ -20,37 +20,37 @@ Typically an object inherits from _EventEmitter_, however our small example belo
2020

2121
## Inheriting From EventEmitter
2222

23-
A perhaps more practical use of `EventEmitter`, and commonly used throughout node is to inherit from it. This means we can leave `EventEmitter`'s prototype untouched, while utilizing its api for our own means of world domination!
23+
A more practical and common use of `EventEmitter` is to inherit from it. This means we can leave `EventEmitter`'s prototype untouched while utilizing its API for our own means of world domination!
2424

25-
To do so we begin by defining the `Dog` constructor, which of course will bark from time to time, also known as an _event_.
25+
To do so, we begin by defining the `Dog` constructor, which of course will bark from time to time (also known as an _event_).
2626

2727
var EventEmitter = require('events').EventEmitter;
2828

2929
function Dog(name) {
3030
this.name = name;
3131
}
3232

33-
Here we inherit from `EventEmitter`, so that we may use the methods provided such as `EventEmitter#on()` and `EventEmitter#emit()`. If the `__proto__` property is throwing you off, no worries! we will be touching on this later.
33+
Here we inherit from `EventEmitter` so we can use the methods it provides, such as `EventEmitter#on()` and `EventEmitter#emit()`. If the `__proto__` property is throwing you off, don't worry, we'll be coming back to this later.
3434

3535
Dog.prototype.__proto__ = EventEmitter.prototype;
3636

37-
Now that we have our `Dog` set up, we can create .... simon! When simon barks we can let _stdout_ know by calling `console.log()` within the callback. The callback it-self is called in context to the object, aka `this`.
37+
Now that we have our `Dog` set up, we can create... Simon! When Simon barks, we can let _stdout_ know by calling `console.log()` within the callback. The callback itself is called in the context of the object (aka `this`).
3838

3939
var simon = new Dog('simon');
4040

4141
simon.on('bark', function(){
4242
console.log(this.name + ' barked');
4343
});
4444

45-
Bark twice a second:
45+
Bark twice per second:
4646

4747
setInterval(function(){
4848
simon.emit('bark');
4949
}, 500);
5050

5151
## Removing Event Listeners
5252

53-
As we have seen event listeners are simply functions which are called when we `emit()` an event. Although not seen often we can remove these listeners by calling the `removeListener(type, callback)` method. In the example below we emit the _message_ "foo bar" every `300` milliseconds, which has the callback of `console.log()`. After 1000 milliseconds we call `removeListener()` with the same arguments that we passed to `on()` originally. To compliment this method is `removeAllListeners(type)` which removes all listeners associated to the given _type_.
53+
As we have seen, event listeners are simply functions which are called when we `emit()` an event. We can remove these listeners by calling the `removeListener(type, callback)` method, although this isn't seen often. In the example below we emit the _message_ "foo bar" every `300` milliseconds, which has a callback of `console.log()`. After 1000 milliseconds, we call `removeListener()` with the same arguments that we passed to `on()` originally. We could also have used `removeAllListeners(type)`, which removes all listeners registered to the given _type_.
5454

5555
var EventEmitter = require('events').EventEmitter;
5656

0 commit comments

Comments
 (0)