Cache per-object data without leaking memory.
Create const cache = new WeakMap(); Then for an object key obj, store cache.set(obj, "data") and read cache.get(obj). WeakMap entries are garbage-collected when the key is no longer referenced.
Sign in to save your code and track progress across devices.