Super Simple EventEmitter
Most examples I see of EventEmitter are quite complicated, so here’s a really simple one:
var events = require("events"); var util = require("util"); var Client = function(){ events.EventEmitter.call(this); this.foo = function(){ this.emit("bar", "HELLO WORLD"); } } util.inherits(Client, events.EventEmitter); var client = new Client(); client.on("bar", function(data){ console.log(data);}); client.foo();
Reply
You must be logged in to post a comment.