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

Localize all vars #2

Closed
Rudxain opened this issue Mar 31, 2022 · 5 comments
Closed

Localize all vars #2

Rudxain opened this issue Mar 31, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@Rudxain
Copy link
Owner

Rudxain commented Mar 31, 2022

Prevents external code from changing the behavior of the library by modifying property values of global objects that some functions depend on. This means using aliases to objects, and copying primitive values

@Rudxain Rudxain added the bug Something isn't working label Mar 31, 2022
@fitiskin
Copy link

Just an idea. Perhaps it would be more convenient to organize the library as a npm package? So that all functions would be available without monkey patching, touching globalThis object and expanding native prototypes such as Number or BigInt.

import { Numeric, Float } from 'well-named-enhanced-js-math-library'

or even

import { modPow } from 'well-named-enhanced-js-math-library/math'

It will allow users to safely use the code in their projects without fear of breaking them with a new suddenly adopted ECMAscript standard.

I would help you with package building, refactoring, and so on.

What do you think?

@Rudxain
Copy link
Owner Author

Rudxain commented Apr 29, 2022

@fitiskin I've been considering doing that. This library includes a lot of stuff that would probably never be added to the official ES spec (like Fibonacci, and inverse factorials), so it shouldn't be used as a polyfill, but rather as a standalone library. Another solution is to remove anything/everything that is not strictly and definitely included in a Stage [1, 4] proposal, ensuring there's more safety about using this as a polyfill. All of the removed functions can then be migrated to my "Useless-Math" repo, and then I would turn that into a non-polyfill standalone library distributed using NPM.

Also, IIFE polyfills ensure everything behaves exactly like built-in methods, so using ESM may not be a good idea for this. I need more info to take a better decision about it.

The problem with my "solution" to remove stuff is that the library would become useless very fast, because core-js already has better polyfills for future JS math, but I want this library to add more stuff because it makes it more unique.

Maybe I should completely abandon the polyfill library concept, and just turn this into a normal library. I could still make polyfills for future stuff, but in smaller quantities, which would make it easier to maintain and change, and I could post them as Gists instead of dedicating entire repos to them.

Thank you for your insight, I'll start thinking more about this

@Rudxain
Copy link
Owner Author

Rudxain commented May 4, 2022

I realized this library wouldn't be useless even after removing everything that is not a Stage +1 proposal. I still haven't made the decision about the future of this library. I'll open a new Issue about this

@Rudxain
Copy link
Owner Author

Rudxain commented Sep 7, 2022

For consistency, I decided that the only global values and fns that should be encapsulated/localized, should be everything but prototype methods, because of the call problem (infinite regress), and because using call makes the code less "elegant". So this library will do the assumption that all prototypes are immutable (even if they aren't)

@Rudxain
Copy link
Owner Author

Rudxain commented May 24, 2024

I've given up on JS, so I'll 🦀RIIR in the future.

I'll keep the JS commit history in a secondary branch, for archiving purposes

@Rudxain Rudxain closed this as not planned Won't fix, can't repro, duplicate, stale May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants