Argument in favor of adding "has" in the WeakMap API

Oliver Hunt oliver at
Wed May 11 13:04:35 PDT 2011

On May 11, 2011, at 12:54 PM, Brendan Eich wrote:

> On May 11, 2011, at 12:44 PM, Oliver Hunt wrote:
>> So you want to do
>> if (map.has(bar))
>>  wiffle = map.get(bar)
>> or some such?
>> The problem here is that you can't guarantee that GC won't happen between those two calls, and therefore you could still end up getting undefined in response to the get.
> Not if bar refers to the key object, since it must be a strong ref.

Re-reading the weakmap definition makes weakmaps seem fundamentally different to any other weakmap API i've ever encountered.  The most common weakmap use cases i am aware of are all essentially caches, and this definition doesn't support that use case at all.

It seems completely bizarre to me that the key should act as a root for the value it is associated with.


More information about the es-discuss mailing list