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 this.foo; }}; // 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 help.

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.

/be

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to