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 authored and evanlucas committed May 17, 2016
1 parent 925fc36 commit d49b49e
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 d49b49e

Please sign in to comment.