Improve portability of the UMD build#328
Open
chocolateboy wants to merge 1 commit intofantasyland:masterfrom
Open
Improve portability of the UMD build#328chocolateboy wants to merge 1 commit intofantasyland:masterfrom
chocolateboy wants to merge 1 commit intofantasyland:masterfrom
Conversation
Member
|
Thanks for the pull request, @chocolateboy! I pushed a few tweaks to your branch. Are you happy with them? |
Author
|
Yes, LGTM, thanks! |
- replace `self` with `globalThis` - make module detection more robust Co-authored-by: David Chambers <dc@davidchambers.me>
cc289e1 to
766faf4
Compare
diasbruno
reviewed
Nov 9, 2024
| module.exports = mapping; | ||
| } else { | ||
| self.FantasyLand = mapping; | ||
| globalThis.FantasyLand = mapping; |
There was a problem hiding this comment.
Wouldn't be safer to use something like (globalThis || self)? Just in case...
Member
There was a problem hiding this comment.
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.
Yeah, you are right. I thought short-circuiting would not throw.
There was a problem hiding this comment.
It'd be worth if it needs to be backward-compatible. But it's hard to find a reliable - and nice - way.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR:
selfwithglobalThisglobalThisis 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.