I would love for this capability to exist with WeakMap's as well. I end up using this pattern quite often for both Map's and WeakMaps.
const Records = new WeakMap();
function getRecord(key) {
let record = Records.get(key);
if (!record) {
record = new Record();
Records.set(key, record);
}
return record;
}
I would love for this capability to exist with WeakMap's as well. I end up using this pattern quite often for both Map's and WeakMaps.