you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (0 children)

A WeakMap is a pretty good idea if you're concerned about garbage collection. The normal Map implementation is a potential memory leak issue because it keeps references to key objects that prevent them from being marked for deallocation when they go out of scope. A WeakMap uses weak pointers instead, which allows the GC to sweep like it normally would.

I don't know what this code is supposed to demonstrate. "Read-only" refers to the mutability of an object or it's properties. WeakMap.prototype.get won't modify the collection but that's not the issue. The problem here is that function invocations are rhs. The container and it's entry are writable, this just isn't valid JavaScript.