Skip to content
This repository was archived by the owner on Apr 3, 2025. It is now read-only.
This repository was archived by the owner on Apr 3, 2025. It is now read-only.

Object with overloads vs ordinary Object #49

Open
@lightmare

Description

@lightmare

Quoting from Avoiding classic pitfalls

When one operand is an ordinary Object and the other is an Object with overloaded operators, the ordinary object is first coerced to some kind of primitive, making it less useful unless both operands were set up for overloading.

Is this restriction really necessary? It prevents any overloads on special-purpose classes working with ordinary objects.
Some examples:

with operators from Set;
set & new Set([2, 3, 5]); // possible ... set intersection
set & [2, 3, 5]; // impossible ... non-primitive
set & map.keys(); // impossible ... non-primitive

with operators from Function;
42 | foo; // possible ... foo(42)
obj | foo; // impossible

with operators from MySerializer;
mySerializer << 42; // possible ... mySerialier.write(42)
mySerializer << obj; // impossible ... non-primitive

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions