Skip to content

Commit 9daf4a2

Browse files
doc: discourage use of util.inherits
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 <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 5a8c66a commit 9daf4a2

File tree

3 files changed

+196
-223
lines changed

3 files changed

+196
-223
lines changed

doc/api/events.md

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,6 @@ The following example shows a simple `EventEmitter` instance with a single
2727
listener. The `eventEmitter.on()` method is used to register listeners, while
2828
the `eventEmitter.emit()` method is used to trigger the event.
2929

30-
```js
31-
const EventEmitter = require('events');
32-
const util = require('util');
33-
34-
function MyEmitter() {
35-
EventEmitter.call(this);
36-
}
37-
util.inherits(MyEmitter, EventEmitter);
38-
39-
const myEmitter = new MyEmitter();
40-
myEmitter.on('event', () => {
41-
console.log('an event occurred!');
42-
});
43-
myEmitter.emit('event');
44-
```
45-
46-
Any object can become an `EventEmitter` through inheritance. The example above
47-
uses the traditional Node.js style prototypical inheritance using
48-
the `util.inherits()` method. It is, however, possible to use ES6 classes as
49-
well:
50-
5130
```js
5231
const EventEmitter = require('events');
5332

0 commit comments

Comments
 (0)