Skip to content

Instantly share code, notes, and snippets.

@zanonnicola
Last active January 5, 2018 17:30
Show Gist options
  • Save zanonnicola/b33d408cde65312bf2ab7104323e8ec0 to your computer and use it in GitHub Desktop.
Save zanonnicola/b33d408cde65312bf2ab7104323e8ec0 to your computer and use it in GitHub Desktop.
A simple polyfill for CustomEvent (support back to any IE 9).
(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