Created
October 19, 2018 17:25
-
-
Save TimVosch/8773d097ec17321871b0fdc4a68ec9e5 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
const EventEmitter = require('events'); | |
const manager = new EventEmitter(); | |
class A { | |
constructor(event) { | |
event.on('event1', this.doSomething); | |
} | |
doSomething(data) { | |
console.log(`Do for ${data}`); | |
} | |
} | |
var aInstance = new A(manager); | |
manager.emit('event1', 'first'); | |
aInstance = new A(manager); | |
manager.emit('event1', 'second'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment