Skip to content

Commit

Permalink
doc: properly inheriting from EventEmitter
Browse files Browse the repository at this point in the history
There are so many buggy code out there, just because not inheriting
properly from `EventEmitter`. This patch gives an official
recommendation.

PR-URL: #2168
Reviewed-By: Jeremiah Senkpiel <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
  • Loading branch information
thefourtheye committed Jul 29, 2015
1 parent 500f253 commit d168d01
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions doc/api/events.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,20 @@ added.
This event is emitted *after* a listener is removed. When this event is
triggered, the listener has been removed from the array of listeners for the
`event`.

### Inheriting from 'EventEmitter'

Inheriting from `EventEmitter` is no different from inheriting from any other
constructor function. For example:

'use strict';
const util = require('util');
const EventEmitter = require('events').EventEmitter;

function MyEventEmitter() {
// Initialize necessary properties from `EventEmitter` in this instance
EventEmitter.call(this);
}

// Inherit functions from `EventEmitter`'s prototype
util.inherits(MyEventEmitter, EventEmitter);

0 comments on commit d168d01

Please sign in to comment.