class-private syntax in ES6 (was: ES6, ES7, ES8 and beyond. A Proposed Roadmap.)

Brendan Eich brendan at mozilla.com
Sun Apr 28 16:43:15 PDT 2013


David Bruant wrote:
> ooooooohh.... Yes it does. I hadn't thought of WeakMaps for the 
> private syntax.
> Sounds good then.

Another point Mark and Tom made that I found helpful:

The traditional GC-costly WeakMap implementation, which handles cases 
where the map and its keys' lifetimes are not related in any particular 
way, to perform cycle collection treating each key/value entry as an 
Ephemeron, is not required for private-in-class. So long as the class 
lives, its private names must work. Instances keep their class alive; 
new instances may be created even if old ones were all GC'ed. Symbols 
are no more leaky that WeakMaps in this setting.

This means that private-in-class names can be per-class as Mark showed, 
but more: the private values may be stored in fields of each instance. 
No WeakMap at full GC cost is required. Whether the implementation uses 
Symbols or GC-optimized WeakMaps is not observable.

As the strawman notes, these private variables's names and values cannot 
be discovered by reflection.

Given all this, I saw light at the end of the tunnel, and sketched 
accordingly in my JQueryUK talk. I tagged the slide's title with 
"(ES6?)" -- note the "?" where elsewhere I used "(ES6)" or "(ES7)" -- 
and made sure not to promise, though.

/be




More information about the es-discuss mailing list