

Ninja Object Properties in JavaScript - mindhunter
http://www.patrick-wied.at/blog/ninja-object-properties-in-javascript

======
lnanek2
It isn't unknown, or even bad practice, to have string values with dots in
them when needed in Java to avoid collisions. For example, the package names
of Android apps use that format, even though the dots in them mean nothing.
Often a constant in a class will have the exact same String value as it's
location:

package blah1.blah2; class Blah3 { private static final String BLAH_KEY =
"blah1.blah2.Blah3.BLAH_KEY"

Which helps a lot when you see the value somewhere else as well. Often if you
are told to put some String keyed values into a general purpose message
container going to another program, the string keys you use again use values
to look like that to avoid collision, as recommended by the Android
documentation itself. Similarly used for persisting application values to a
single XML file. Then of course we also have technologies like GWT, where
programmers write in Java, and it is compiled to JavaScript. I could easily
see that generating property names with packages in them.

So anyway, you see dots for sub-objects, but you also see dots simply as part
of a way to avoid name collisions, as in Java package naming and sharing
String key namespace best practices. Just because it isn't used for sub-
objects or method calls or properties doesn't mean it is wrong or bad.

~~~
pa7
hey, I'm the author of the article. I didn't write that using dots in the
property name is a bad practice, but rather that other parts of the code let
me assume that they didn't know a lot about js

------
KyleHill
Remember, \u200B is also valid in property names, making it immune to

for(i in x){ console.log(i, "_"); }

as well. That said, this is the worst idea.

------
jQueryIsAwesome
It gets even more weird when using Unicode imperceptible characters

    
    
        x = {}
        x[String.fromCharCode(1)] = "1"
        x[String.fromCharCode(2)] = "2"
        x[String.fromCharCode(3)] = "3"
    

And obligatory reference to namespace function (to easily create namespaced
modules): [http://www.codeproject.com/Articles/19030/Namespaces-in-
Java...](http://www.codeproject.com/Articles/19030/Namespaces-in-JavaScript)

