Use cases for WeakMap

Erik Corry erik.corry at gmail.com
Mon May 16 00:10:14 PDT 2011


2011/5/16 Brendan Eich <brendan at mozilla.com>:
> On May 15, 2011, at 11:53 PM, Erik Corry wrote:
>
>> 2011/5/16 Brendan Eich <brendan at mozilla.com>:
>>> This is a good point too. Not sure we've considered a value -> value map carefully yet.
>>
>> A value->anything map is pretty easy to do with a normal JS object.
>>
>> function get(value) {
>>  if (typeof(value) == 'number') return this["NUM" + value];
>>  if (typeof(value) == 'string') return this["STR" + value];
>>  ...
>> }
>
> Where's the 'object' case (excluding null)?

Elided for clarity :-)  It can be implemented with private names or
WeakMaps.  My point was we don't need to think about maps with values
as keys.  We have that already.

-- 
Erik Corry


More information about the es-discuss mailing list