>From my perspective as a JS programmer, overloading the dot seems confusing.
The gains in elegance don't appear to me to be worth it. However,
overloading [] might be more acceptable:
let x = new PrivateName();
// or perhaps:
private x;
function Point()
{
this[x] = 100;
}
function createPoint()
{
return {
[x]: 100,
};
}
function expando(obj)
{
obj[x] = 100; // OK even if object is not extensible
}
The extension of the object literal syntax to include [identifier] would be
a general nicety for me. There might be complications that I don't see, of
course. Thanks for letting me intrude!
Kevin
On Wed, Dec 22, 2010 at 10:27 AM, Kyle Simpson <[email protected]> wrote:
> What about adding an attribute to properties that somehow
>> identify which classes (in the prototype chain for protected)
>> have access to the object? I'll leave the "somehow" up in the
>> air, but you could introduce a [[Private]] attribute which, if not
>> undefined, says which context must be set (and for protected,
>> either directly or through the prototypal chain of the current
>> context) to gain access to this property. And if that context is
>> not found, some error is thrown. Maybe it would be
>> [[EncapsulationType]] :: {private, protected, public} and
>> [[EncapsulationContext]] :: <?>. You could also add a simple api
>> to check for these (isPrivate, isProtected, isPublic,
>> hasEncapsulatedProperty, etc) depending on how it would affect
>> "in" and enumeration.
>>
>
> I’m assuming (perhaps incorrectly) that this suggestion is to model the
> flag of the private vs. non-private as a “property descriptor” that can be
> set by `Object.defineProperty()`. Am I correct?
>
> If so, I think that makes a lot of sense. I would like `private` to work
> that way.
>
> Of course, the setting of `private` would probably have to be one-way, like
> `configurable` is, so that such a property could be made un-private by
> another context.
>
> BTW, pardon (and ignore) me if I just stepped on an ant-bed and confused
> the whole topic. I’ve been following this thread silently and mostly felt
> like it was much more complicated than I could understand. Peter’s post was
> the first one that seemed to make sense. :)
>
> --Kyle
>
>
>
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss