tc39 / proposal-operator-overloading

MIT License
622 stars 20 forks source link

<=> starship operator for unified overloading of comparison operators #24

Open c69 opened 4 years ago

c69 commented 4 years ago

Following the same logic that led to its inclusion into C++20: https://devblogs.microsoft.com/cppblog/simplify-your-code-with-rocket-science-c20s-spaceship-operator/

ljharb commented 4 years ago

The spaceship operator would be a different proposal; if that proposal existed, it would have to figure out how it interacted with operator overloading as part of figuring out cross-cutting concerns within stage 1.

bergus commented 3 years ago

The current readme states "The definition of >, <= and >= is derived from <". I think it would be quite nice if the Operators function would also accept an object with a "<=>"(a, b) method instead of a "<"(a, b) method, with the same interface as a .sort() comparison function. We shouldn't introduce <=> itself as new syntax in JS in this proposal.

jhmaster2000 commented 2 years ago

As an alternative to this, implicitly overloaded operators by the JS engine itself: #53

ljharb commented 2 years ago

Here's the notes from when a spaceship operator was rejected: https://github.com/tc39/notes/blob/167155eeb708d84e1758d99c88b15670f9b81f75/meetings/2020-06/june-4.md#conclusionresolution-2