diff options
author | Sakthipriyan Vairamani <thechargingvolcano@gmail.com> | 2015-07-12 16:10:57 +0000 |
---|---|---|
committer | Sakthipriyan Vairamani <thechargingvolcano@gmail.com> | 2015-07-29 14:57:58 +0530 |
commit | d168d01b04cefafcdcb2b88d489d2ed0b7a15154 (patch) | |
tree | 874e357a632a8dcdcfaf6cd445cb5fe17aa539df /doc | |
parent | 500f2538cc00d389a22b6ddcdd51d2af2c4a7478 (diff) | |
download | android-node-v8-d168d01b04cefafcdcb2b88d489d2ed0b7a15154.tar.gz android-node-v8-d168d01b04cefafcdcb2b88d489d2ed0b7a15154.tar.bz2 android-node-v8-d168d01b04cefafcdcb2b88d489d2ed0b7a15154.zip |
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>
Diffstat (limited to 'doc')
-rw-r--r-- | doc/api/events.markdown | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/doc/api/events.markdown b/doc/api/events.markdown index e7470f37aa..fbc04a9623 100644 --- a/doc/api/events.markdown +++ b/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); |