// In contrast to the Set which can be a collection of anything, Weakset is only a collection of objects and not of arbitrary values of any type.
// The WeakSet is weak: References to objects in the collection are held weakly: if there is no other reference to an object stored in the WeakSet, they can be garbage collected.
// Also, WeakSets are not enumerable and so you don’t get enumeration methods like .forEach, .clear etc.
var ws = new WeakSet();
var obj = {};
var foo = {};
ws.add(window);
ws.add(obj);
ws.has(window); // true
ws.has(foo); // false, foo has not been added to the set
ws.delete(window); // removes window from the set
ws.has(window); // false, window has been removed
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.