Throw a link with a tutorial where the creation of a module with a class is described. When you call a module, a new object is created for which events you can hang handlers.

How many google, but so far I come across only the most primitive articles, and I can not find a simple module with the necessary functionality to peep the code.

  • you would specify the task, otherwise a spherical horse in vacuum is obtained - deivan_

1 answer 1

Here is the simplest example of a module exporting a class that generates events every n milliseconds.

 var events = require('events'); exports.sampleEventer = function(interval, caller_name){ this.interval = interval; this.caller_name = caller_name; this.goForvard = function(){ var me = this; setInterval(function() { me.emit('some_event', me.caller_name); }, me.interval); } } exports.sampleEventer.prototype = new events.EventEmitter;