Skip to content

Instantly share code, notes, and snippets.

@ivarconr
Created May 14, 2018 11:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivarconr/67647a190e64707a99d831ae41026b3c to your computer and use it in GitHub Desktop.
Save ivarconr/67647a190e64707a99d831ae41026b3c to your computer and use it in GitHub Desktop.
// Create and add EventListner
const func = ev => {console.log(ev.detail)};
const listner = window.addEventListener('demo', func);
// Publish custom event
const event = new CustomEvent('demo', {detail: 'hello world'});
window.dispatchEvent(event);
// Remove EventListner
window.removeEventListener('demo', func);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment