Creating a WeakMap object
suggest changeA WeakMap stores key/value pairs. Unlike a Map, its keys must be objects and are held weakly. If nothing else still refers to a key, the garbage collector may remove that entry. Using a primitive as a key throws TypeError.
The constructor takes an optional iterable of pairs (for example an array). Each pair is a two-element array.
const o1 = {a: 1, b: 2},
o2 = {};
const weakmap = new WeakMap([[o1, true], [o2, o1]]);
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents