There is a need to write a console utility that, depending on the user's choice, will launch a specific algorithm. The algorithm needs to be made modular, consisting of a given list of tasks. I want to implement the tasks in the form of separate classes of modules that will be interconnected by an event model. A simple example below.
// main.js 'use strict'; const EventEmitter = require('events'); class MyEmitter extends EventEmitter {} const myEmitter = new MyEmitter(); let _first = require('./first'); let _second = require('./second'); let map = new Map(); map.set('first', new _first(myEmitter)); map.set('second', new _second(myEmitter)); myEmitter.emit('start', 3); // first.js module.exports = function First(Emiter) { Emiter.on('start', (x) => { console.log('an event occurred! in First. get: ' + x++); Emiter.emit('next', x); }); } // second.js module.exports = function Second(Emiter) { Emiter.on('next', (x) => { console.log('an event occurred! in Second, get: ' + x); }); } How is this approach usable? Are there any negative aspects in the declaration of the handler functions in the constructor?