WeakMap better than Private Symbols? (was: direct_proxies "problem")

Brendan Eich brendan at mozilla.com
Thu Jan 10 09:03:08 PST 2013


Domenic Denicola wrote:
> From: Brandon Benvie [brandon at brandonbenvie.com]
> Sent: Thursday, January 10, 2013 11:50
>
>> They both have their place since there's many uses for both inherited and non-inherited private values.
>
> Of course, (non-)inheritance is a great point.
>
> Amusingly, using "conventional" OO terminology, it seems private symbols give you something like "protected" and weak maps give you "private".

Private symbols can give you true privacy. Just confine that symbol!

The distinction for OO fans that I see is class-private vs. 
instance-private: a well-confined private symbol for a prototype method, 
e.g., gives you class-private methods. A WeakMap keyed by instance 
identity, like the closure pattern for OO in JS, gives you instance-private.

/be


More information about the es-discuss mailing list