-
Notifications
You must be signed in to change notification settings - Fork 1
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
Should min and max be optional? #9
Comments
A few misc thoughts. Math.clamp(n, 0) I don't like this. This is basically a shorthand for clamping at a lower-bound, and it just feels wrong for this shorthand to only exist for lower bounds and not upper bounds. I'd rather this just isn't supported, and it gives a TypeError if you tried to do it. I also find it very unintuitive to read code like this. Math.clamp(42) // => 42 This is just silly. ideally it wouldn't be allowed, but there's not really any harm in allowing it either, since there's no practical reason to ever see this kind of thing. Math.clamp(n, 0, null);
Math.clamp(n, null, 360); I find these forms to be useful. You can technically accomplish the same thing with infinity, but I think it's a (tiny) bit more expressive to use a nullish value here instead. Math.clamp(n, 0, undefined);
Math.clamp(n, undefined, 360); If using However, I would find it weird if It also feels really weird to write So, in the end, it feels like I have this competing set of ideals where I'm going to have to give up something, but I don't know what I would want to give up. Perhaps my preference would be to make all parameters required and non-nullish, and if you want to omit a lower or upper bound, you have to use an infinity - but I don't really know. |
I am preferring 3 personally and a few other delegates I spoke to hinted towards that option as well; there seems to be a precedent lately to be more strict with argument count. Possibly you could pass undefined/null explicitly but still require 3 arguments, and it could be then default to +-Infinity but undecided on that. |
This would make it more cumbersome to use than userland...
We can still keep them optional, and in this case you would still use |
fwiw TC39 will no longer be coercing things in new APIs, which means that |
Made all required in 513523e |
If it did coerce, I assume it would coerce to zero, correct? In my examples, I was assuming that But I'm good with |
Personally unsure currently. Options:
See: https://github.com/tc39/how-we-work/blob/main/normative-conventions.md#when-required-arguments-are-missing-throw
The text was updated successfully, but these errors were encountered: