About private names

Mike Shaver mike.shaver at gmail.com
Sun Mar 20 16:47:42 PDT 2011

On Mar 20, 2011 3:34 PM, "Kyle Simpson" <getify at gmail.com> wrote:
>> BTW, if you know that a property name is foo, why would you ever code
obj["foo"] instead of obj.foo?
> The most obvious reason is if the name of the property contains a
character which cannot be an identifier character in the property name...
like a unicode character, for instance.

"Unicode characters" (non-ASCII) other than whitespace are pretty much all
permissible in property names via dot syntax, FWIW. Lambda and pi are the
most common, though I've seen other math/greek as well.

A property name with whitespace is not expressible with dot syntax, but
unlikely to be used except in object-as-hashtable cases.

> Are we talking about the difference between obj['foo'] and obj[foo]? I
think perhaps that was a subtle shift in this conversation that I missed
until just now?
> Without private names, is there (and what is it?) an important distinction
> 1. obj[foo] and obj.foo; AND
> 2. obj['foo'] and obj.foo

The former case of #1 refers to a property named by the value of the
variable |foo|. All other cases refer to a property named "foo". So the
cases in #2 are equivalent, but the ones in #1 are not.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110320/47606faf/attachment.html>

More information about the es-discuss mailing list