| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f5ca39d commit 9593b35
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -43,21 +43,21 @@ myEmitter.emit('event'); | |||
| 43 | 43 | ## Passing arguments and `this` to listeners | |
| 44 | 44 | ||
| 45 | 45 | 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 | ||
| 49 | 49 | listener is attached. | |
| 50 | 50 | ||
| 51 | 51 | ```js | |
| 52 | 52 | const myEmitter = new MyEmitter(); | |
| 53 | 53 | myEmitter.on('event', function(a, b) { | |
| 54 | - console.log(a, b, this); | ||
| 54 | + console.log(a, b, this, this === myEmitter); | ||
| 55 | 55 | // Prints: | |
| 56 | 56 | // a b MyEmitter { | |
| 57 | 57 | // domain: null, | |
| 58 | 58 | // _events: { event: [Function] }, | |
| 59 | 59 | // _eventsCount: 1, | |
| 60 | - // _maxListeners: undefined } | ||
| 60 | + // _maxListeners: undefined } true | ||
| 61 | 61 | }); | |
| 62 | 62 | myEmitter.emit('event', 'a', 'b'); | |
| 63 | 63 | ``` | |
| Back | FazBrowse Home | New Git URL |
0 commit comments