2022年4月5日 星期二

dispatchEvent

https://developer.mozilla.org/en-US/docs/Web/Events/Creating_and_triggering_events

const
cancelled = !cb.dispatchEvent(event);
=>利用
dispatchEvent確認是否已經取消事件的預設行為(preventDefault)
另外
dispatchEvent會觸發DOM nodes的event loop

dispatchEvent: 送出事件給所有有訂閱的監聽者
https://jim-5.gitbook.io/javascript-tip/shi-jian#shi-jian-chu-li-mo-xing

EventTarget.dispatchEvent()

false
 if event is cancelable, and at least one of the event handlers which received event called Event.preventDefault(). Otherwise true.

EventTarget 接口
https://www.bookstack.cn/read/javascript-tutorial/docs-events-eventtarget.md

Event 对象
https://www.bookstack.cn/read/javascript-tutorial/docs-events-event.md

demo:
https://jsbin.com/vesidoz/edit?html,js,console,output
https://jsbin.com/vuyapeh/edit?html,js,console,output