Private symbols as WeakMap sugar

Herby Vojčík herby at mailbox.sk
Thu Jan 17 06:01:09 PST 2013



Brendan Eich wrote:
> David Bruant wrote:
>> Hi,
>>
>> This is an idea naturally derived of all the current discussions about
>> WeakMaps and Private symbols. The proposal is easily summarized by
>> these lines of code:
>>
>> var wm = new WeakMap();
>> var o = {};
>> o[wm] = 12 // desugars to wm.set(o, 12)
>> var a = o[wm]; // desugars to wm.get(o);
>> wm in o // desugars to wm.has(o);
>> delete o[wm] // desugars to wm.delete(o);
>
> You are not showing the desugaring in general:
>
> function get(o,x) {
> return o[x];
> }
>
> must transform to
>
> function get(o,x) {
> return (x is WeakMap) ? x.get(o) : o[x];
> }

I'd go for genericity here:
   function get(o,x) {
     return x.@@isReversedPseudoProperty ? x[o] : o[x];
   }

combined with OMR which gives WeakMap x[o] ability, it could be generic 
and allow other "reversed getters".

> This is not an acceptable hit for every []-named property access.
>
> /be

Herby


More information about the es-discuss mailing list