Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version for node? #5

Open
mitra42 opened this issue Nov 21, 2017 · 1 comment
Open

Version for node? #5

mitra42 opened this issue Nov 21, 2017 · 1 comment

Comments

@mitra42
Copy link

mitra42 commented Nov 21, 2017

I'm trying to add CustomEvent so that a library I've built will work in both browser and Node. Your code looks like its what is needed EXCEPT it calls document.createEventObject, and in node there is document.createEvent, but not document.createEventObject.

Do you know of a version of custom-event that works in Node? Or is there a way to add that functionality.

@mitra42
Copy link
Author

mitra42 commented Nov 22, 2017

A bit of digging and I've found a solution for myself which is to define "document" before requiring custom-event, however this breaks the common practice of requiring everything at the top of the file BEFORE creating anything.

I could also get it to work by replacing the line

('undefined' !== typeof document && 'function' === typeof document.createEvent) ? function CustomEvent (type, params) {

with

('undefined' === typeof document || 'function' === typeof document.createEvent) ? function CustomEvent (type, params) {

Since the IE9 version is fine for node, and document will have been defined before CustomEvent gets called.

That might be a good alternative ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant