I\'m writing a class
and want the instances to be comparable by <
, >
, ==
.
For <
and ><
You seem to be looking for hash consing, but as you experienced this cannot be implemented efficiently since JavaScript does not (yet) support weak (or soft) references.
No, it is not possible to overwrite any operators, including ==
, in JS. ==
will always compare two objects by reference, there's nothing you can do about it. Your best bet will be creating a compare
method.