Actual WeakSet Use Cases

Tab Atkins Jr. jackalmage at gmail.com
Tue Jun 2 15:51:47 UTC 2015


On Tue, Jun 2, 2015 at 8:45 AM, Benjamin Gruenaum <benjamingr at gmail.com> wrote:
> Thanks Domenic,
>
> Elaborating on your example with more details. Let's say you need to make
> sure at a certain point that an object has not been tinkered with by user
> code (for security reasons). You can't check the prototype or a symbol since
> those can be faked and you can't keep a regular `Set` because that would
> prevent any `Foo` object from ever being garbage collected.

Exactly.  WeakSet's use-cases are all in the same family as WeakMap,
just with a simpler set-up - rather than associating arbitrary data
with the object, you just associate "is in this set" with it.

~TJ


More information about the es-discuss mailing list