Skip to content

Instantly share code, notes, and snippets.

@farinspace
Last active November 15, 2019 17:30
Show Gist options
  • Save farinspace/5fc83dcc2fbf50188f901e84069cf9d8 to your computer and use it in GitHub Desktop.
Save farinspace/5fc83dcc2fbf50188f901e84069cf9d8 to your computer and use it in GitHub Desktop.
CustomEvent() polyfill
/**
* CustomEvent() polyfill
*
* https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent#Polyfill
* https://caniuse.com/#feat=customevent
* https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Creating_and_triggering_events
*/
(function(){
if (typeof window.CustomEvent === "function") return false;
function CustomEvent(event, params) {
params = params || { bubbles: false, cancelable: false, detail: undefined };
var evt = document.createEvent('CustomEvent');
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
return evt;
}
CustomEvent.prototype = window.Event.prototype;
window.CustomEvent = CustomEvent;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment