Ducks, Rabbits, and Privacy

Benoit Marchant marchant at
Thu Jan 24 09:02:48 PST 2013

On Jan 24, 2013, at 5:47, Kevin Smith <khs4473 at> wrote:

>> Why would you use a square bracket notation rather than a . Property access notation?
>> [] is typically only use when the property name is in a variable, which is not the case when you write your own object.
> True - but for symbols, your only option is square brackets:
>     var sym = new Symbol(), obj = {};
>     obj[sym] = 42;
> So if you go the private symbols route, then you're going to have *lots* of square brackets.

Not in the case where you would use a private property like a regular one if the language were to offer to tag properties as private, right?

I guess I don't quite understand why it seems contentious to add a "private" property to property descriptors which already "reserve" properties like "value", "enumerable" or "writable". 

"private" is a meta description of a property like "value", "enumerable" or "writable.

That feels a more natural extension than adding class to the language.

Since on the topic of adding more property descriptors, one thing we played with in Montage is the notions of "distinct" property descriptor. One amazing aspect of Ecmascript's prototyping inheritance is it's ability to allow you to set default values on the objects that one use as prototypes for others. This is a one time operations, compared to setting initial default state per instance creation, being in a constructor or init method. It's really efficient in term of memory footprint as well, and the prototype lookup is so optimized now that it works well.
There's however a big problem with mutable objects like arrays because if it's on the prototype, it's shared by all instances. When that's what you want and sometime you do, great. But if what you had in mind was that each object should have it's own array for that property, debugging the fist time is fun!
Yes, you can do that in a constructor or init method. But another way is to add to the property descriptor a property "distinct": true . Which means that each object inheriting from that object would get it's own copy of that object at creation time.

One problem we found working on that is that unfortunately the language let you add these properties to the object used as property descriptors but it's lost after that, meaning that you need to keep a parallel storage to keep track of it.

All this is more declarative than imperative since you can do it yourself in constructor/init method, but it adds semantic and cut down code to write, while being executed in native code by the language itself.

Just wanted to share that.



> { Kevin }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list