Hacker News new | ask | show | jobs
by catapart 669 days ago
This might not be a good use case because I just started doing it and never found a good reason to stop, but I use WeakMaps for keeping references to HTML elements at runtime in library code where I don't want to require a constructor/deconstructor pattern.

Basically, I use them as a reference for DOM elements that my library will do work on, since I can't predict when that DOM element will no longer be a viable reference. And for that - yeah, I can certainly see some benefits to making the thing iterable. Not that I've hit any roadblocks replacing the WeakMap with an array didn't fix. Just that my library array will keep the ref alive until the dev dismisses it. Being able to iterate on WeakMaps would at least give that memory back.