mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-27 14:21:00 +00:00
22 lines
493 B
JavaScript
22 lines
493 B
JavaScript
function EventEmitter() {
|
|
this.events = {};
|
|
}
|
|
|
|
EventEmitter.prototype.on = function (eventName, callback) {
|
|
if (!this.events[eventName]) {
|
|
this.events[eventName] = [];
|
|
}
|
|
this.events[eventName].push(callback);
|
|
};
|
|
|
|
EventEmitter.prototype.emit = function (eventName) {
|
|
var args = Array.prototype.slice.call(arguments, 1);
|
|
if (this.events[eventName]) {
|
|
this.events[eventName].forEach(function (callback) {
|
|
callback.apply(null, args);
|
|
});
|
|
}
|
|
};
|
|
|
|
module.exports = new EventEmitter();
|