About private names
dean at deanlandolt.com
Sun Mar 20 12:49:58 PDT 2011
On Sun, Mar 20, 2011 at 3:36 PM, Allen Wirfs-Brock <allen at wirfs-brock.com>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. BTW, if you know that a property name is foo, why
> would you ever code obj["foo"] instead of obj.foo? [ ] should only be
> needed if the property name is not an identifier or is a computed value
> (hence my original example).
In order to demonstrate the `obj["foo"] === obj.foo` equality you're example
would need to set the foo identifier to "foo" instead of 0. I don't know if
this behavior is explicitly promised as an invariant by the language but
it's certainly something we've all come to expect. I remember this coming up
once before WRT private names -- perhaps the benefits outweigh the costs of
breaking this expectation, but it's definitely surprising.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss