Skip to content

Commit

Permalink
doc: discourage use of util.inherits
Browse files Browse the repository at this point in the history
util.inherits breaks the prototype chain. A fix does not seem
useful, since ES6 extends provides language level support for the
same functionality.

This commit starts fasing out mentions of the method.

Fixes: #6512
Fixes: #4179

PR-URL: #6514
Reviewed-By: James Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
eljefedelrodeodeljefe committed May 9, 2016
1 parent 5a8c66a commit 9daf4a2
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 223 deletions.
21 changes: 0 additions & 21 deletions doc/api/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,6 @@ The following example shows a simple `EventEmitter` instance with a single
listener. The `eventEmitter.on()` method is used to register listeners, while
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);

const myEmitter = new MyEmitter();
myEmitter.on('event', () => {
console.log('an event occurred!');
});
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');

Expand Down
Loading

0 comments on commit 9daf4a2

Please sign in to comment.