I need to create an EventEmitter
class with constructor()
and on(eventName, callback)
methods. Also have to make Movie
a subclass of EventEmitter
and use the inherited methods to publish play
event when the method is called. I don't know how to create subclasses because I can't find examples using class
.
After this I need to create a Logger
class with constructor()
and log(info)
methods.
I need to do this:
terminator.on('play', () => logger.log('play'));
terminator.play(); // output: The 'play' event has been emitted
This is what I have until now:
class Movie{
constructor(name){
this.name = name;
}
play(){
//not important I think
}
class Logger{
constructor(){
//not sure
}
log(info){
console.log("The '" + info +"' event has been emitted");
}
}
class EventEmitter{
constructor(){
//not sure
}
on(eventName, callback) {
//idk
}
}