About private names

Andrew Dupont mozilla at andrewdupont.net
Sun Mar 20 12:49:37 PDT 2011

OK, you lost me.

On Mar 20, 2011, at 2:36 PM, Allen Wirfs-Brock wrote:

> On Mar 20, 2011, at 10:55 AM, Andrew Dupont wrote:
>> Right; I think Dean and I are saying that this would be the first time obj.foo meant something different from obj['foo']. And to ascertain that those two meant different things, I'd have to go searching through the code for a `private foo` declaration.
> With the private name proposal obj.foo and obj.[#.foo] will always mean the same thing regardless of whether foo is scoped as a private name or as a regular property name.

I'm not comparing `obj.foo` and `obj[#.foo]`; I get that those two are equivalent for private names. (I don't know what you mean when you say those are the same for public names, though, because I don't know what `obj[#.foo]` means in a public context.)

> BTW, if you know that a property name is foo, why would you ever code obj["foo"] instead of obj.foo?

The proposal strongly implies that the `private` declaration affects only "a property name on the right of . or the left of : in an object initialiser." Does it also affect bracket notation? In other words:

private foo;
obj.foo = 42;
obj['foo'] === obj.foo; // true or false?

If the answer is `false`, that's your answer for why I'd ever code `obj['foo']` instead of `obj.foo`. If the answer is `true`, then that answers one of the questions I was asking earlier; but it also means that there's no way to get around the fact that the `private` declaration is "shadowing" any possible use of a public property name called `foo` in the same lexical scope.


More information about the es-discuss mailing list