Hi folks,
I have a function myFunction in separate someFile.js file:
var EventEmitter = require("events");
var MyFunction = function() {
...
return this;
}
module.exports = MyFunction;
I create an object of that function in another js file, and I want to attach an event handler to it:
const MyFunction = require('./lib/ParticleSwarmOptimizer');
var myFunctionObject = MyFunction();
myFunctionObject.on("someEvent", function() {...});
But I keep getting the error "TypeError: myFunctionObject.on is not a function".
I have tried to do it like in this tutorial, like in this tutorial (section "Implement a custom class based on EventEmitter") and like in Node-RED's Node.js file.
But I keep getting the same error over and over again. Still getting nuts from this kind of constructions in Javascript
Can somebody correct my code snippet to emit an event in the function, and listen to those events in the handler?
Thanks a lot !!!
Bart