Node.js Cannot read property 'on' of undefined
You forgot to return the event emitter from your v
function:
var v = function() {
var e = new events();
e.emit('start');
return e;
};
Also notice that the start
event will not be called because you have emitted the event before you subscribed to it. So you could kind of rework your code a little:
var events = require('events').EventEmitter;
var v = function() {
var e = new events();
return e;
};
var r = v();
r.on('start', function(){
console.log('event start just fired!!!!!!!!!!');
});
// emit the event after you have subscribed to the start callback
r.emit('start');