4 ms·
Yeah, no. Bad idea. I could very easily see an evolution speed run here where people do for…of on the weakmap, make closures that use those values and the clos
by steelbrain 2y ago
Yeah, no. Bad idea.
I could very easily see an evolution speed run here where people do for…of on the weakmap, make closures that use those values and the closure references cause nothing in the WeakMap to do its job, which is get garbage collected.
Then we’ll see a submission on HN that says no, weakmaps should be weak…maps. Followed by intense wars on X/Twitter and then the next version of whatever linter is popular at the time adding linting rules that forbid people from iterating on weak maps.
- bjoli 2y agoThat sums up the arguments as: 1. Iterable weakmaps would be very usable to - among other things - foreign runtimes in JavaScript 2. People who don't know what they are doing can do dumb things with weak references. Both are of course valid, but in this case I do think that linters telling people that they have to know what they are doing are the better option.
- zarzavat 2y agoYou can already build iterable WeakMaps. And people do, because they need iterable WeakMaps. Your argument applies just as much to iterable WeakMaps distributed as libraries as it does to iterable WeakMaps distributed with the browser.