doc: properly inheriting from EventEmitter

There are so many buggy code out there, just because not inheriting
properly from `EventEmitter`. This patch gives an official
recommendation.

PR-URL: https://github.com/nodejs/io.js/pull/2168
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
pull/2168/merge
Sakthipriyan Vairamani 2015-07-12 16:10:57 +00:00
parent 500f2538cc
commit d168d01b04
1 changed files with 17 additions and 0 deletions

View File

@ -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);