krambuhl / custom-event-polyfill

Polyfill for creating CustomEvents on IE9/10/11 if native implementation is missing.
MIT License
112 stars 19 forks source link

Expose CustomEvent as Event #6

Closed akegalj closed 7 years ago

akegalj commented 7 years ago

IE11 (and maybe older versions as well) on new Event() would fail with:

Object doesn't support this action

this resolves the issue.

krambuhl commented 7 years ago

I don't quite understand the reason for this change. Ostensibly, if window.Event is not a function, then it will not have a prototype, which is required for CustomEvent.prototype = window.Event.prototype.

CustomEvent.prototype = window.Event.prototype;
window.CustomEvent = CustomEvent;
if(typeof window.Event !== 'function') {
  window.Event = CustomEvent; // this doesn't even have a protoype?
}

Details please 😄 An minimal example would be great.

akegalj commented 7 years ago

In my defense I don't know much about javascrip in general but firefox and chrome has this behavior firefox and IE11 (and probably the rest of IE) this: ie11 - win7

so from my noob perspective there is prototype for window.Event defined that we can use in CustomEvent but we can't initialize function with new as we can in firefox. Please correct me if I am talking nonsense

This function https://github.com/alexmingoia/purescript-pux/blob/master/src/Pux/Router.js#L37 is failing in IE, but with this PR it works great. Maybe it is just a hack, I can't tell, but it works.

krambuhl commented 7 years ago

I would recommend you PR the purescript-pux project to use new CustomEvent instead of new Event. Internet Explorer does not define new Event as a Constructor, this polyfill does not change that behavior.

If you need to shim the described behavior for your project, adding window.Event = window.CustomEvent would be just fine. Please let me know if this is problematic.

akegalj commented 7 years ago

would recommend you PR the purescript-pux project to use new CustomEvent instead of new Event. Internet Explorer does not define new Event as a Constructor, this polyfill does not change that behavior.

I agree. Thank you for investing time and discussing this with me. Will open issue in purescript-pux project tomorrow morning.

If you need to shim the described behavior for your project, adding window.Event = window.CustomEvent would be just fine. Please let me know if this is problematic

yes I know, thanks for the advice. I just thought that should be task for polyfill, as I understand term polyfill in this area means it should make some feature compatible across browsers. We already have working version for this problem, I was just confused why not to fix it upstream. Anyway, will ping purescript-pux guys and ask their opinion about this.

Thanks <3