Ducks, Rabbits, and Privacy

Brendan Eich brendan at
Thu Jan 24 10:10:56 PST 2013

Benoit Marchant wrote:
> 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.

As David wrote, this does not work in a dynamic language.

function generic_get(obj, prop) {
     return obj[prop];

obj = {private foo: 42, get bar() { return; }}; // or 
equivalent class syntax

// elsewhere
var steal = generic_get(obj, 'foo');

How do you enforce that only bar can access foo from obj? A private 
attribute on a property with a public string-equated name 'foo' does not 

The mistake is treating name privacy as a property attribute. Privacy is 
not an attribute of property descriptors, it's a restriction on property 
names. It is not a static restriction in any sense, rather a capability. 
If you keep the private symbol or weak map confined, privacy is assured.


More information about the es-discuss mailing list