3 ms·
Modern JavaScript also supports ephemerons. There it's the WeakMap type: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakM
by jlokier 4y ago
Modern JavaScript also supports ephemerons.
There it's the WeakMap type: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
WeakMap prevents observing when the weakly referenced key objects are garbage collected. It does this by being deliberately non-enumerable (see the MDN link). So it may be considered missing part of the definition of ephemerons. It has the weak-key part without the finalizer part.
But modern browsers support WeakRef and FinalizationRegistry, which eventually reveal when objects have been garbage collected. https://v8.dev/features/weak-references https://v8.dev/features/weak-references, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... and https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
So this part of the WeakMap design is just an annoying obstacle which can be worked around.
(Note, as FinalizationRegistry is designed to accompany WeakRef, it's intriguing that MDN lists Opera as supporting FinalizationRegistry but not WeakRef.)