Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9593b35

Browse filesBrowse 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 <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
1 parent f5ca39d commit 9593b35
Copy full SHA for 9593b35

File tree

Expand file treeCollapse file tree

1 file changed

+5
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+5
-5
lines changed
Open diff view settings
Collapse file

‎doc/api/events.md‎

Copy file name to clipboardExpand all lines: doc/api/events.md
+5-5Lines changed: 5 additions & 5 deletions
  • Display the source diff
  • Display the rich diff
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.