Commit de6f931
docs: Fix EventEmitter initialization example (nodejs#245)
## Description
We should consider using `new` keyword to properly instantiate EventEmitter class object, otherwise we get an error (as per current docs example):
```js
const eventEmitter = require('events').EventEmitter()
eventEmitter.on('start', () => {
console.log('started')
})
```
ends up with:
```
TypeError: Cannot read property 'on' of undefined
```
Whereas instantiating with `new`:
```js
const EventEmitter = require('events')
const eventEmitter = new EventEmitter()
console.log(eventEmitter instanceof EventEmitter) // true
eventEmitter.on('start', () => {
console.log('started')
})
eventEmitter.emit('start')
```
outputs:
```
true
started
```
## Related Issues
Fixes #2421 parent ee75a04 commit de6f931
1 file changed
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
0 commit comments