事件即“发布/订阅”模式,⾃定义事件即“消息发布”,事件的监听即“订阅订阅”
JS 原⽣⽀持⾃定义事件
document.createEvent(type); // 创建事件
event.initEvent(eventType, canBubble, prevent); // 初始化事件
target.addEventListener('dataavailable', handler, false); // 监听事件
target.dispatchEvent(e); // 触发事件
JS 原⽣⽀持⾃定义事件
本文来自博客园,作者:jialiangzai,转载请注明原文链接:https://www.cnblogs.com/zsnhweb/p/19030748