UNPKG

mgk.js

Version:

epik framework for creating simple 2d games with web technologies, this package is new so 100% there might be bugs(entire package not working could also be the case) PLUSS this is open-source (can access it via github: https://github.com/helloworld190/MGK

23 lines (19 loc) 502 B
export class EventEmitter { constructor() { this.listeners = {}; } on(event, callback) { if (!this.listeners[event]) this.listeners[event] = []; this.listeners[event].push(callback); } off(event, callback) { if (!this.listeners[event]) return; this.listeners[event] = this.listeners[event].filter((cb) => cb !== callback); } emit(event, ...args) { if (!this.listeners[event]) return; for (const cb of this.listeners[event]) { cb(...args); } } }