21 lines
497 B
JavaScript
21 lines
497 B
JavaScript
class EventListener {
|
|
constructor () {
|
|
this._listeners = {};
|
|
}
|
|
emit (eventName, ...data) {
|
|
if (!this._listeners[eventName] || this._listeners[eventName].length == 0) return;
|
|
|
|
for (var e = 0; e < this._listeners[eventName].length; e++) {
|
|
this._listeners[eventName][e](...data);
|
|
}
|
|
}
|
|
on (eventName, callback) {
|
|
if (!this._listeners[eventName]) this._listeners[eventName] = [];
|
|
this._listeners[eventName].push(callback);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
"EventListener": EventListener
|
|
};
|