Reputation: 96
my custom event type not working in nodejs EventEmitter. I have create a custom event type named "someMethod" but it's not working. It's not showing anything in console. Please view my code described below:
util = require('util');
var EventEmitter = require('events').EventEmitter;
//Here is the MyClass constructor:
var MyClass = function() {
}
util.inherits(MyClass, EventEmitter);
MyClass.prototype.someMethod = function() {
this.emit("customEvent", "arg1", "arg2");
};
var myInstance = new MyClass();
myInstance.on('customEvent', function(str1, str2) {
console.log('got a custom event with the str1 %s and str2 %s!', str1, str2);
});
Upvotes: 1
Views: 630
Reputation: 106696
You're not calling myInstance.someMethod()
so that the event can be emitted.
Upvotes: 2