Better HN
top
new
best
ask
show
jobs
Log in
Sign up
Better HN
Comment
by
phpnode
· 10y ago · 0 comments
Unfortunately your example won't work. You can't use a primitive value as a key in a weak map, which negates many of their possible use cases.
Comments
[–]
wwwigham
10y ago
You're right, I hadn't realized that the spec forbade primitives as WeakMap keys - so while to approach should actually work in other languages, in JS it would leak memory as you'd be forced to use a normal map (or clean up after yourself - ich).
[–]
tylorr
10y ago
Yeah, weak map have weak references to the keys, not the values.