В общем чета типа:
function EventEmmiter() {
}
// ... реализуем интерфейс EventEmmiter
/*
* @inherits EventEmmiter
*
*/
function Controller() {
EventEmitter.call(this);
}
Controller.prototype = Object.create(EventEmitter.prototype, {
constructor: {value: Controller}
});
Controller.prototype.updateDiv = function() {
utils.request('some/url', this.onDivContentLoaded.bind(this));
};
Controller.prototype.onDivContentLoaded = function(data) {
document.querySelector('div').innerHTML = data;
this.dispatchEvent('divupdated', {data: data});
};
var controller = new Controller();
controller.addEventListener('divupdated', function() {
alert('Div was updated');
});
controller.updateDiv();