3 ms·
Unfortunately your example won't work. You can't use a primitive value as a key in a weak map, which negates many of their possible use cases.
by phpnode 10y ago
Unfortunately your example won't work. You can't use a primitive value as a key in a weak map, which negates many of their possible use cases.
- wwwigham 10y agoYou're right, I hadn't realized that the spec forbade primitives as WeakMap keys - so while to approach should actually work in other languages, in JS it would leak memory as you'd be forced to use a normal map (or clean up after yourself - ich).
- tylorr 10y agoYeah, weak map have weak references to the keys, not the values.