Skip to content

Instantly share code, notes, and snippets.

@mantismamita
Last active January 9, 2020 10:28
Show Gist options
  • Save mantismamita/0c83e133efe1874614cdae1922623f1f to your computer and use it in GitHub Desktop.
Save mantismamita/0c83e133efe1874614cdae1922623f1f to your computer and use it in GitHub Desktop.
Creates a custom event
function setCustomEvent (dispatcher, eventName, dataObj) {
let event
if (window.CustomEvent) {
event = new CustomEvent(eventName, { detail: dataObj })
} else {
event = document.createEvent('CustomEvent')
event.initCustomEvent(eventName, true, true, dataObj)
}
return dispatcher.dispatchEvent(event)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment