Open hifizz opened 5 years ago
以下代码请直接打开 console 运行
const div = document.createElement("div")
const buildEvent = new Event("build")
div.addEventListener("build", (event) => {
console.log(event);
}, false)
div.dispatchEvent(buildEvent)
const deployEvent = new CustomEvent("deploy", {
detail: "Dummy data, whatever you like.",
bubbles: true,
cancelable: true,
composed: true
})
div.addEventListener("deploy", (event) => {
console.log(event)
}, false)
div.dispatchEvent(deployEvent)
适用场景:需要解决回调函数解耦的场景。