About private names

Sam Tobin-Hochstadt samth at ccs.neu.edu
Sun Mar 20 13:39:22 PDT 2011


On Sun, Mar 20, 2011 at 3:49 PM, Andrew Dupont <mozilla at andrewdupont.net> wrote:
>
>> 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?

Assuming that we hadn't previously set obj['foo'], then 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.
>



-- 
sam th
samth at ccs.neu.edu


More information about the es-discuss mailing list