Created
February 1, 2018 11:05
-
-
Save AaronFlower/69757d734adc3c33c079a0f60b05d525 to your computer and use it in GitHub Desktop.
fix window.CustomEvent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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