Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: discourage use of util.inherits; point to es6 extends #6514

Closed
wants to merge 6 commits into from
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