Skip to content

Commit 9593b35

Browse files
dagolinuxoidMylesBorins
authored andcommitted
doc: clarify this in event listeners
this === eventEmitter or this === instance of EventEmitter, but it's this is not EventEmitter. PR-URL: #20537 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]>
1 parent f5ca39d commit 9593b35

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

doc/api/events.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,21 @@ myEmitter.emit('event');
4343
## Passing arguments and `this` to listeners
4444

4545
The `eventEmitter.emit()` method allows an arbitrary set of arguments to be
46-
passed to the listener functions. It is important to keep in mind that when an
47-
ordinary listener function is called by the `EventEmitter`, the standard `this`
48-
keyword is intentionally set to reference the `EventEmitter` to which the
46+
passed to the listener functions. It is important to keep in mind that when
47+
an ordinary listener function is called, the standard `this` keyword
48+
is intentionally set to reference the `EventEmitter` instance to which the
4949
listener is attached.
5050

5151
```js
5252
const myEmitter = new MyEmitter();
5353
myEmitter.on('event', function(a, b) {
54-
console.log(a, b, this);
54+
console.log(a, b, this, this === myEmitter);
5555
// Prints:
5656
// a b MyEmitter {
5757
// domain: null,
5858
// _events: { event: [Function] },
5959
// _eventsCount: 1,
60-
// _maxListeners: undefined }
60+
// _maxListeners: undefined } true
6161
});
6262
myEmitter.emit('event', 'a', 'b');
6363
```

0 commit comments

Comments
 (0)