News for hackers. Stuff that matters.
Re:New JavaScript Set Methods by postalrat on Monday June 24, 2024 @04:47PM (#40780558)
You can use objects and other things as keys for a Set or Map. As far as I know you can't do that for objects.

    const s = new Set();

    const a = {}, b = {};

    s.add(a);

    s.has(a); // true

    s.has(b); // false


    const o = {};

    o[a] = true;

    o[a]; // true

    o[b]; // true, cause its cast to a string like "[object Object]"
I've also seen Map perform faster than using an object as a Map.
Re:New JavaScript Set Methods by brobdingnag_pp on Monday June 24, 2024 @05:36PM (#40781098)
Beware of a gotcha here: object keys are tested for strict equality and not deep equality, in other words add/get must use the same object instance and not just an object with the same keys/values