-
Notifications
You must be signed in to change notification settings - Fork 22
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
Suggesion: Define Operators with functions #56
Comments
I’m pretty sure this would slow down all code using any overloadable operators, because the engine would have to check if the operands had operators defined. |
@ljharb I doubt that für three reasons:
|
Serious code does that with Date objects all the time - lots of existing things use valueOf/toString/Symbol.toPrimitive to “overload” objects. |
@ljharb At this point we would really need some data. Sadly, I lack the resources to scrape GitHub or npm scanning how often that is actually used. My gut still says that it will not be too much (at least if you neglect built-in classes like Date for which operator overloading could be prohibited). |
Date means that all objects must always be checked, on many websites - github/npm data won’t change that. |
I don't get it, consider current |
I think the goal is not in perfomance but in the fact that it will return your
|
@FrameMuse I think once again operator overloading comes down to what it always comes down to: Only use it if there is exactly one logical implementation. |
@FrameMuse I think you misunderstand my question, I asked that question because of #56 (comment) . |
@hax Yes, I did, sorry. Thank you for pointing it out. |
That depends on the implementation of the operator.
|
Analogous to
Object.defineProperty
/Object.defineProperties
we could haveObject.defineOperator
/Object.defineOperators
to define operators for objects/prototypes. This would be in line with current designs for defining things for objects. Like withObject.defineProperty
trying to re-define a previously defined operator for an object should throw.Typescript definition
Examples
Design goals
any
orunknown
)The text was updated successfully, but these errors were encountered: