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

Simplify polyfills to work like other Sugar methods. #577

Open
andrewplummer opened this issue Jan 15, 2017 · 1 comment
Open

Simplify polyfills to work like other Sugar methods. #577

andrewplummer opened this issue Jan 15, 2017 · 1 comment
Labels

Comments

@andrewplummer
Copy link
Owner

Requiring or including Sugar polyfills currently immediately apply the polyfill to the global object. For example, the es6 module (which is included in the default package) immediately applies the polyfill for Array#find and others.

Although polyfills are safer to apply to the global object than other methods, considering that Sugar has made concessions about not modifying the global scope by default for other methods, as well as the concept of ponyfills becoming a thing, it may be a good time to reconsider making an exception for polyfills. This would also have the advantage of being simpler to handle in the code, and simpler to grasp for users as well. Polyfills would of course use native methods when they are available.

One potential issue here is that Sugar provides "enhanced" methods, such as array methods like every, which allow shortcuts like every(1) etc. Since these "ponyfills" could be called directly through the global object (i.e. Sugar.Array.every) it would become necessary to create a distinction between the ponyfill and the enhanced method signatures.

@andrewplummer
Copy link
Owner Author

One idea to handle enhancements is to have an enhance method on both the Sugar global and namespaces like Sugar.Array. This could accept a prefix option that would allow enhanced methods to exist separate to polyfills/ponyfills:

Sugar.Array.enhance({
  prefix: 'enhanced'
});
Sugar.Array.every(...); // The ponyfill method
Sugar.Array.enhancedEvery(...); // The enhanced method

Without the prefix, the method would simply be overwritten for people who prefer that. This is nice because it would maintain parity with enhance (#562).

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

No branches or pull requests

1 participant