Created
March 28, 2016 11:13
-
-
Save ismnoiet/a82ba7bb7329237b0b34 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//first.js | |
var util = require('util'), | |
EventEmitter = require('events'); | |
function First () { | |
EventEmitter.call(this) | |
} | |
util.inherits(First, EventEmitter); | |
First.prototype.sendMessage = function (msg) { | |
this.emit('message', {msg:msg}); | |
}; | |
module.exports = First; | |
// second.js : | |
var First = require('./first.js'); | |
var firstEvents = new First(); | |
// listen for the 'message event from first.js' | |
firstEvents.on('message',function(data){ | |
console.log('recieved data from first.js is : ',data); | |
}); | |
// to emit message from inside first.js | |
firstEvents.sendMessage('first message from first.js'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment