Skip to content

Instantly share code, notes, and snippets.

@AaronFlower
Created February 1, 2018 11:05
Show Gist options
  • Select an option

  • Save AaronFlower/69757d734adc3c33c079a0f60b05d525 to your computer and use it in GitHub Desktop.

Select an option

Save AaronFlower/69757d734adc3c33c079a0f60b05d525 to your computer and use it in GitHub Desktop.
fix window.CustomEvent
/**
* CustomEvent polyfill
* https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent#Polyfill
*/
(function () {
try {
// a : While a window.CustomEvent object exists, it cannot be called as a constructor.
// b : There is no window.CustomEvent object
new window.CustomEvent('T');
} catch (e) {
var CustomEvent = function (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