Private Slots

Herby Vojčík herby at mailbox.sk
Tue Jan 15 12:06:07 PST 2013



David Bruant wrote:
>> ES6 provides WeakMaps and Proxies. Why not see what people do with
>> those before introducing private slots?
> I wouldn't be opposed to that, but that's just my opinion. Still,
> private symbols allow property-like syntax. I haven't followed the

Hm. If this would be the best benefit (and putting aside the issue of 
WeakMap GC cost for a moment), one may think about "property-like 
access, but with reversed responsibilities" which could allow for easing 
things like that. For example, if I abused @ character for that (as a 
replacement for .), I could write:

   foo.bar at baz.quux
to mean
   baz[foo.bar].quux // reversed access, ie WeakMap

and

   foo.bar at baz(quux)
to mean
   baz(foo.bar, quux) // more functional OO-like

(not necessarily the same syntax, just the idea, that, instead of 
private slots, one can provide "reversal" into the language allowing to 
use certain pattern easier)

Herby

> latest developments of how classes and private symbols interact, but I'm
> not too worried it goes well. Assuming it does, it makes it easy for
> people to use actually private properties in their code, lowering the
> barrier to writing well-encapsulated code.
>
> David


More information about the es-discuss mailing list