3 ms·
Once ES6 support is everywhere, you should be able to use WeakMap and WeakSet. [0] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Obj
by TheAceOfHearts 11y ago
Once ES6 support is everywhere, you should be able to use WeakMap and WeakSet.
[0] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- jvilk 11y agoActually, those are not sufficient to implement weak references, and have a much different use case! With WeakMap and WeakSet, the keys are weakly referenced, hence the names. If you have a WeakMap, you can't produce a value stored in the map without a strong reference to a key. You can actually polyfill WeakMap and WeakSet. You can't do the same for weak references.
- jvilk 11y agoI misspoke -- you can polyfill WeakSet, but you cannot polyfill WeakMap, since you do not know when you can shrink the map. (But you still cannot use it to emulate weak references, since you need a strong reference to get data out of the map.)