News for hackers. Stuff that matters.
Re:New JavaScript Set Methods by zarzavat on Monday June 24, 2024 @11:39AM (#40777358)
Objects not really safe to use as sets:

    const x = {};
    ‘constructor’ in x // true
    x[‘constructor’] === Object // true
You have to use hasOwnProperty and people don’t remember to do this.

Some properties cannot be deleted, and some cannot be modified:

    delete x.constructor;
    x.constructor === undefined // false
    x.__proto__ = undefined;
    x.__proto__ === undefined // false
Sets also allow you to have sets of other types rather than just strings and symbols.
Re:New JavaScript Set Methods by threatofrain on Monday June 24, 2024 @12:14PM (#40777856)
If you do use objects I might suggest Object.create(null).
Re:New JavaScript Set Methods by tracker1 on Monday June 24, 2024 @12:56PM (#40778339)
+1 Was going to be my response as well...
Re:New JavaScript Set Methods by kevincox on Monday June 24, 2024 @04:15PM (#40780189)
Yup. I always use Set and Map over objects. They just contain way fewer surprises and the APIs actually work as you would expect. I only use Objects for "struct" like objects with a known set of keys that are used by name. It is also nice because it conveys more intent to the reader.