I need to store weak referenced object with its id
(integer) and get the object later by id
. And I will expect getting undefined
or null
from the id
once it's GCed.
ES2015 introduces WeakMap
and WeakSet
. However they both don't allow primitive types as key and don't allow iteration.
Is it possible to achieve this?
NOTE: I'm aware that WeakMap
and WeakSet
are weak in keys. I'm asking whether it is possible to implement function mentioned above, via WeakSet
or WeakMap
or other ways in JS.