Open jdegoes opened 5 years ago
Unfortunately not. JavaScript's WeakMap
lacks several fundamental features compared to Java's. In particular, it does not provide iteration of keys/entries (on purpose).
To implement java.util.WeakHashMap
, we will need something more, which might be coming with a proposal for WeakRef
s: https://github.com/tc39/proposal-weakrefs
Seems that WeakRefs are now present in majority (by market share) of browsers: https://www.caniuse.com/?search=weakref https://github.com/tc39/proposal-weakrefs/pull/212/files
WeakRef
s are now at Stage 4, so we could now implement this. PR welcome.
j.u.WeakHashMap
can now be implemented in this repo, on top of WeakReference
and ReferenceQueue
.
Could be based on
WeakMap
, supported since ECMAScript 6 (2015) and on all major browsers.