Skip to content

WeakSet

A WeakSet object is a collection of unique objects (no primitive values). References to objects in a WeakSet are held weakly, so they do not prevent garbage collection if there are no other references to the object. WeakSet elements are not iterable.

add(value) function

Add a new object to the WeakSet if it is not already present. The value must be an object.

value: The object to add.

Returns: The WeakSet object (for chaining).

has(value) function

Return a boolean indicating whether an object is present in the WeakSet.

value: The object to check.

Returns: True if the object is in the WeakSet, otherwise false.

delete(value) function

Remove the specified object from the WeakSet, if it exists.

value: The object to remove.

Returns: True if the object was present and removed, otherwise false.