I've came across this WeakRef polyfill: ungap / weakrefs.
I'm struggling to understand how it works, particularly at line 11-14:
var wr = new WeakMap;
function WeakRef(value) {
wr.set(this, value);
}
So there is a global WeakMap wr
.
And a constructor-like function WeakRef
that takes a value
and stores it in wr
, using this
(the resulting object) as key.
My understanding is the wr
global WeakMap wouldn't drop the inserted value
until the key is dropped. In this case, the key is the resulting WeakRef object.
So value
wouldn't be allowed to be GC-ed until the created WeakRef is dropped.
Wouldn't this make the polyfill a strong reference?