-
Notifications
You must be signed in to change notification settings - Fork 377
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
Improve portability of the UMD build #328
base: master
Are you sure you want to change the base?
Conversation
Thanks for the pull request, @chocolateboy! I pushed a few tweaks to your branch. Are you happy with them? |
Yes, LGTM, thanks! |
- replace `self` with `globalThis` - make module detection more robust Co-authored-by: David Chambers <[email protected]>
cc289e1
to
766faf4
Compare
module.exports = mapping; | ||
} else { | ||
self.FantasyLand = mapping; | ||
globalThis.FantasyLand = mapping; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't be safer to use something like (globalThis || self)
? Just in case...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If globalThis
does not exist in the environment, globalThis || self
throws a ReferenceError. We would need to use typeof globalThis
to first check for the presence of globalThis
. Is this worthwhile? I'm not sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you are right. I thought short-circuiting would not throw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be worth if it needs to be backward-compatible. But it's hard to find a reliable - and nice - way.
This PR:
self
withglobalThis
globalThis
is the official way to refer to the global scope and is supported by almost all environments:The notable exception is IE11, which will need to use a polyfill. If IE11 support was previously promised or assumed, then this would be a breaking change.