Promise polyfill should be injectable by loaders, instead of relying on global scope pollution
See original GitHub issueMost.js relies on ES6 Promises but does not offer a way to import a polyfill for them cleanly without polluting the global scope. This is important in particular when you are writing code that should integrate with third parties within one browser context.
For AMD loaders this can be fixed by having Most.js resolve the global Promise
through a module. A "most/promise"
module could be defined as simply as
define([], function() { return Promise });
This module could then at a user’s discretion be remapped using AMD map
configuration to their own, user-defined module that can in turn provide a polyfill for Most.js to use, without requiring the user to pollute the global browser environment with a polyfill implementation written into window.Promise
.
Surely other loaders and bundlers support similar extension points.
Issue Analytics
- State:
- Created 6 years ago
- Comments:16 (5 by maintainers)
Top GitHub Comments
Hey @rjgotten,
Hmmm… I don’t think it does. I didn’t test the resulting code, but it certainly looks like it doesn’t pollute the global scope to me. Unless I’m missing something, it looks like it creates a module-scoped
Promise
instance, and since most.js doesn’t specifically look in the global scope, it uses it. No???Personally, I think this is the best way to allow people to use a local implementation of a normally global object. If Promises were just another third-party utility, then I’d be 100% agreeing with you. However, they’re equivalent to
Array
,RegExp
, etc. now.I know it kinda sucks dealing with browsers, but library authors need to work towards standards and the future. 😃
I don’t understand why it’s considered “pollution” to have Promise in the global scope. Why is that polluting the global scope, but all other standard native types are not pollution? (Map, Set, setTimeout, etc.) Promise is found in the global scope in every modern JavaScript VM. Asking for it to not be in the global scope sounds like asking for special behaviour that deviates from the modern standard.