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

Web compatibility #4

Open
zloirock opened this issue Mar 28, 2022 · 9 comments
Open

Web compatibility #4

zloirock opened this issue Mar 28, 2022 · 9 comments
Labels
question Further information is requested

Comments

@zloirock
Copy link

zloirock commented Mar 28, 2022

As I already wrote, Function.prototype.once is available in SugarJS (and IIRC in some other libraries). At the current meeting, it was decided to rename Array.prototype.groupBy because of a similar conflict with SugarJS. Because of this, I see 2 options for avoid this possible conflict:

@js-choi
Copy link
Collaborator

js-choi commented Mar 28, 2022

Thanks for raising this issue.

From what I recall, SugarJS stopped conditionally monkey-patching Function.prototype around 2016 (see also Bugzilla 1750812). So this partially depends on whether there are any codebases still in use today that use that old version of SugarJS. (As long as the monkey-patching is not conditional, then it’s okay, but the old version of SugarJS did conditionally monkey-patch, which is why Array.prototype.groupBy broke code that used the old version. 😔)

We will have to determine whether that old version of SugarJS also monkey-patched in Function.prototype.once.

We will also have to closely analyze Sugar.js’s Function.prototype.once’s behavior and determine which of the options in #2 it matches. It seems like it does cache results, but there are other subtleties that we will have to confirm…

And, yes, we could always use another method name; see #1.

I will be presenting this tomorrow, and I have added this unfortunate issue to my slides. I will also fix the explainer’s section when I have time.

@js-choi js-choi added the question Further information is requested label Mar 28, 2022
@hax
Copy link
Member

hax commented Mar 29, 2022

I assume static Function.once do not have webcompt issue?

@zloirock
Copy link
Author

@hax SugarJS - only in case that no one used it as a shortcut for Function.prototype.once.

A simple search on GitHub shows many cases usage of static Function.once like this.

@js-choi
Copy link
Collaborator

js-choi commented Mar 29, 2022

What matters is if the monkey patching of Function (or Function.prototype) is conditional. Unconditional monkey patching won’t be affected by extending the built-in. At least V4Core’s monkey patching does not seem to conditional, so that’s good.

@hax
Copy link
Member

hax commented May 24, 2022

One possible solution of webcomp is using meta method syntax, function.once or do.once ( do.once may be not good for this proposal, but do.pipe seems ok for Function.pipe proposal.)

@ljharb
Copy link
Member

ljharb commented May 24, 2022

that would be pretty annoying to be forced to wrap it in a function in order to pass it elsewhere; it’d also make it impossible to polyfill.

@hax
Copy link
Member

hax commented May 24, 2022

Yeah, so I think Function.xxx should be the first choice for helpers proposals.

But if we are considering some syntax proposal, for example, extensions or call-this proposal, we could consider something like value->do.pipe(f) (or value->let(f) if use Kotlin-style name).

@js-choi
Copy link
Collaborator

js-choi commented Jul 10, 2022

But if we are considering some syntax proposal, for example, extensions or call-this proposal, we could consider something like value->do.pipe(f) (or value->let(f) if use Kotlin-style name).

Although I applaud the creativity; this proposal is for a tiny convenience function. I think it doesn’t deserve the huge complexity burden of new syntax. 🙂

There are always alternative names if the pre-2016-SugarJS problem ends up being insurmountable, even if they are worse than once. Like oneTime and onlyOnce and singleTime and limitOne.

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

No branches or pull requests

5 participants