by
1
4
262k
0
Top 1% !
Popular
Pearl of Wisdom
Specified
Popularity: 4929th place
No tags for this snippet yet.
LanguageJavaScript
LicenseMIT_X11
SourceGitHub
SourceMyGists

An example of inheriting from event emitter

An example of inheriting from event emitter: 
EventEmitterPattern.js
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/267376/An-example-of-inheriting-from-event-emit?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
// Require our emitter var Emitter = require('events').EventEmitter; // Our main constructor var myEmitter = function (config) { // extend with emitter Emitter.call(this); }; // Inherit from emitter, but keep my constructor myEmitter.prototype = Object.create(Emitter.prototype, { constructor: { value: myEmitter } }); // methods myEmitter.prototype.setName = function (nam) { this.name = nam; this.emit('nameChanged', name); }; module.exports = myEmitter;
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus