We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
class Event { constructor() { this.handlers = {}; // 事件中心 } // 添加事件句柄 addEventListener(type, handler) { if (!(type in this.handlers)) { this.handlers[type] = []; } this.handlers[type].push(handler); } // 分发事件句柄 dispatchEvent(type) { if (!(type in this.handlers)) { return new Error("not descibe this event!"); } const args = Array.from(arguments).slice(1); this.handlers[type].forEach(handler => handler(...args)); } // 移除事件或者移除事件句柄 removeEvent(type, handler) { if (!(type in this.handlers)) { return new Error("not descibe this event!"); } // 如果没有传入事件直接移除该订阅 if (!handler) delete this.handlers[type]; else { this.handlers[type].splice(handler, 1); } } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
1.订阅发布
The text was updated successfully, but these errors were encountered: