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?
It really is strong reference.
Why couldn't they just mention that in the README. Or maybe atleast leave the issue mentioning this open??
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With