Hi I\'m tyring to implement observer pattern in JavaScript:
My index.js:
$(document).ready(function () {
var ironMan = new Movie();
class EventObserver {
constructor () {
this.observers = []
}
subscribe (fn) {
this.observers.push(fn)
}
unsubscribe (fn) {
this.observers = this.observers.filter(subscriber => subscriber !== fn)
}
broadcast (data) {
this.observers.forEach(subscriber => subscriber(data))
}
}
Or you can use EventEmitter in NodeJs https://nodejs.org/api/events.html#events_class_eventemitter