new EventEmitter() → {EventEmitter}
EventEmitter implements basic event emitting logics.
EventEmitter implements basic event emitting logics. It also provides function that augments the ability to other objects.
- Source:
Returns:
- Type
- EventEmitter
Examples
var eventEmitter = EventEmitter(['event1', 'event2']);
var eventHandler = function(event) {
console.log(event.detail);
};
var obj = {
handleEvent: function(event) {
console.log(event.detail);
}
};
eventEmitter.addEventListener('event1', eventHandler);
eventEmitter.addEventListener('event2', obj);
eventEmitter._emitEvent('event1', 'value1'); // value1
eventEmitter._emitEvent('event2', 'value2'); // value2
Extending from EventEmitter:
var NewModule = Module.create(function() {
this.super(EventEmitter).call(this, ['event1', 'event2']);
}).extend(EventEmitter);
var module = NewModule();