Browse Source

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>
v4.0.0-rc
Sakthipriyan Vairamani 9 years ago
parent
commit
d168d01b04
  1. 17
      doc/api/events.markdown

17
doc/api/events.markdown

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

Loading…
Cancel
Save