JavaScript Tutorial ✦
WeakSet and WeakMap
Use weak references for keys, allowing garbage collection if only referenced in the collection.
const wm = new WeakMap();
const ws = new WeakSet();
const obj = {};
wm.set(obj, 'value');
ws.add(obj);
Use weak references for keys, allowing garbage collection if only referenced in the collection.
const wm = new WeakMap();
const ws = new WeakSet();
const obj = {};
wm.set(obj, 'value');
ws.add(obj);