CustomEvent & Event
js 自定义事件
const event = new CustomEvent(typeArg, customEventInit);
// add an appropriate event listener
obj.addEventListener("cat", function(e) { process(e.detail) });
// create and dispatch the event
var event = new CustomEvent("cat", {
detail: {
hazcheeseburger: true
}
});
obj.dispatchEvent(event);
// doc is a reference to the content document
function dispatchCustomEvent(doc) {
var eventDetail = Components.utils.cloneInto({foo: 'bar'}, doc.defaultView);
var myEvent = doc.defaultView.CustomEvent("mytype", eventDetail);
doc.dispatchEvent(myEvent);
}
https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent
https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent
Event
const event = new Event('build');
// Listen for the event.
elem.addEventListener('build', function (e) { /* ... */ }, false);
// Dispatch the event.
elem.dispatchEvent(event);
https://developer.mozilla.org/en-US/docs/Web/Guide/Events/
https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Creating_and_triggering_events
postMessage
https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage
Event Emitter
refs
©xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!