summaryrefslogtreecommitdiff
path: root/doc/api/events.md
diff options
context:
space:
mode:
authorDaniel Bevenius <daniel.bevenius@gmail.com>2016-11-08 21:04:57 +0100
committerDaniel Bevenius <daniel.bevenius@gmail.com>2016-11-16 07:52:57 +0100
commit367065be4be33dac6e0c325f88dfa1fac1314903 (patch)
treebdfadf72df864915d38384b2c1bf8ddd402d922d /doc/api/events.md
parent5242114d89652a217880c0a0f216bf46a51c1379 (diff)
downloadandroid-node-v8-367065be4be33dac6e0c325f88dfa1fac1314903.tar.gz
android-node-v8-367065be4be33dac6e0c325f88dfa1fac1314903.tar.bz2
android-node-v8-367065be4be33dac6e0c325f88dfa1fac1314903.zip
doc: make comment indentation consistent
Currently, some of the docs use different indentation for comments in the code examples. This commit makes the indentation consistent by putting the comments at the beginning of the line (really no indentation that is). PR-URL: https://github.com/nodejs/node/pull/9518 Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Diffstat (limited to 'doc/api/events.md')
-rw-r--r--doc/api/events.md62
1 files changed, 31 insertions, 31 deletions
diff --git a/doc/api/events.md b/doc/api/events.md
index 3cca1ada5b..b468674c36 100644
--- a/doc/api/events.md
+++ b/doc/api/events.md
@@ -51,12 +51,12 @@ listener is attached.
const myEmitter = new MyEmitter();
myEmitter.on('event', function(a, b) {
console.log(a, b, this);
- // Prints:
- // a b MyEmitter {
- // domain: null,
- // _events: { event: [Function] },
- // _eventsCount: 1,
- // _maxListeners: undefined }
+ // Prints:
+ // a b MyEmitter {
+ // domain: null,
+ // _events: { event: [Function] },
+ // _eventsCount: 1,
+ // _maxListeners: undefined }
});
myEmitter.emit('event', 'a', 'b');
```
@@ -68,7 +68,7 @@ the `this` keyword will no longer reference the `EventEmitter` instance:
const myEmitter = new MyEmitter();
myEmitter.on('event', (a, b) => {
console.log(a, b, this);
- // Prints: a b {}
+ // Prints: a b {}
});
myEmitter.emit('event', 'a', 'b');
```
@@ -103,9 +103,9 @@ myEmitter.on('event', () => {
console.log(++m);
});
myEmitter.emit('event');
- // Prints: 1
+// Prints: 1
myEmitter.emit('event');
- // Prints: 2
+// Prints: 2
```
Using the `eventEmitter.once()` method, it is possible to register a listener
@@ -119,9 +119,9 @@ myEmitter.once('event', () => {
console.log(++m);
});
myEmitter.emit('event');
- // Prints: 1
+// Prints: 1
myEmitter.emit('event');
- // Ignored
+// Ignored
```
## Error events
@@ -137,7 +137,7 @@ stack trace is printed, and the Node.js process exits.
```js
const myEmitter = new MyEmitter();
myEmitter.emit('error', new Error('whoops!'));
- // Throws and crashes Node.js
+// Throws and crashes Node.js
```
To guard against crashing the Node.js process, a listener can be registered
@@ -152,7 +152,7 @@ process.on('uncaughtException', (err) => {
});
myEmitter.emit('error', new Error('whoops!'));
- // Prints: whoops! there was an error
+// Prints: whoops! there was an error
```
As a best practice, listeners should always be added for the `'error'` events.
@@ -163,7 +163,7 @@ myEmitter.on('error', (err) => {
console.log('whoops! there was an error');
});
myEmitter.emit('error', new Error('whoops!'));
- // Prints: whoops! there was an error
+// Prints: whoops! there was an error
```
## Class: EventEmitter
@@ -214,9 +214,9 @@ myEmitter.on('event', () => {
console.log('A');
});
myEmitter.emit('event');
- // Prints:
- // B
- // A
+// Prints:
+// B
+// A
```
### Event: 'removeListener'
@@ -245,7 +245,7 @@ const myEmitter = new MyEmitter();
myEmitter.on('event', () => {});
myEmitter.on('event', () => {});
console.log(EventEmitter.listenerCount(myEmitter, 'event'));
- // Prints: 2
+// Prints: 2
```
### EventEmitter.defaultMaxListeners
@@ -323,7 +323,7 @@ const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
- // Prints [ 'foo', 'bar', Symbol(symbol) ]
+// Prints: [ 'foo', 'bar', Symbol(symbol) ]
```
### emitter.getMaxListeners()
@@ -356,7 +356,7 @@ server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
- // Prints: [ [Function] ]
+// Prints: [ [Function] ]
```
### emitter.on(eventName, listener)
@@ -390,9 +390,9 @@ const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
- // Prints:
- // b
- // a
+// Prints:
+// b
+// a
```
### emitter.once(eventName, listener)
@@ -423,9 +423,9 @@ const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
- // Prints:
- // b
- // a
+// Prints:
+// b
+// a
```
### emitter.prependListener(eventName, listener)
@@ -530,15 +530,15 @@ myEmitter.on('event', callbackB);
// callbackA removes listener callbackB but it will still be called.
// Internal listener array at time of emit [callbackA, callbackB]
myEmitter.emit('event');
- // Prints:
- // A
- // B
+// Prints:
+// A
+// B
// callbackB is now removed.
// Internal listener array [callbackA]
myEmitter.emit('event');
- // Prints:
- // A
+// Prints:
+// A
```