Skip to content

Instantly share code, notes, and snippets.

@tonysamperi
Created October 17, 2018 12:58
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 tonysamperi/0e73f8489000e8261600a92af92748c1 to your computer and use it in GitHub Desktop.
Save tonysamperi/0e73f8489000e8261600a92af92748c1 to your computer and use it in GitHub Desktop.
new CustomEvent polyfill (new Event) for IE 9, IE10, IE11
/**
* Modern browsers already support new CustomEvent
* Remember to switch to CustomEvent in your application
*/
// If IE
if (typeof w.CustomEvent !== typeof isNaN) {
const customEvent = function (event, params) {
params = params || {bubbles: false, cancelable: false, detail: undefined};
const evt = document.createEvent("CustomEvent");
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
return evt;
};
customEvent.prototype = w.Event.prototype;
w.CustomEvent = customEvent;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment