Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 3 additions & 20 deletions doc/api/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,8 @@ the `eventEmitter.emit()` method is used to trigger the event.

```js
const EventEmitter = require('events');
const util = require('util');

function MyEmitter() {
EventEmitter.call(this);
}
util.inherits(MyEmitter, EventEmitter);
class MyEmitter extends EventEmitter {}

const myEmitter = new MyEmitter();
myEmitter.on('event', () => {
Expand All @@ -44,21 +40,8 @@ myEmitter.emit('event');
```

Any object can become an `EventEmitter` through inheritance. The example above
uses the traditional Node.js style prototypical inheritance using
the `util.inherits()` method. It is, however, possible to use ES6 classes as
well:

```js
const EventEmitter = require('events');

class MyEmitter extends EventEmitter {}

const myEmitter = new MyEmitter();
myEmitter.on('event', () => {
console.log('an event occurred!');
});
myEmitter.emit('event');
```
uses the ES6 classes. It is however possible to use traditional Node.js style
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'the ES6 classes'? I'd drop the reference to util.inherits() entirely, by the way.

prototypical inheritance using the `util.inherits()` method.

## Passing arguments and `this` to listeners

Expand Down
Loading