javascript-collections-framework
    Preparing search index...

    Interface Equatable

    An object that defines its own value equality.

    Implement both methods, consistently: a[equalsSymbol](b) must be symmetric and transitive, and equal objects must return the same [hashCodeSymbol](hash). Use hash for nested values so they hash the same way the caller does. Value equality applies only when both values implement the protocol; an object implementing only one of the two methods is rejected when it is hashed.

    class Point implements Equatable {
    constructor(readonly x: number, readonly y: number) {}
    [equalsSymbol](other: unknown): boolean {
    return other instanceof Point && other.x === this.x && other.y === this.y
    }
    [hashCodeSymbol](hash: HashFunction): number {
    return hash(this.x) * 31 + hash(this.y)
    }
    }
    interface Equatable {
        "[equalsSymbol]"(other: unknown): boolean;
        "[hashCodeSymbol]"(hash: HashFunction): number;
    }
    Index
    • Returns whether other equals this object; called only when other also implements the protocol.

      Parameters

      • other: unknown

      Returns boolean

    • Returns this object's hash; use hash for nested values. Equal objects return equal numbers.

      Parameters

      Returns number