Javascript namespace conventions [closed]
I have namespaced my javascript.
Are there any conventions used with regards to capitalisation and casing of namespace names?
Is it ok to have a namespace in the form MyNamespace
so when accessing a property or function 开发者_如何学CI use MyNamespace.myProperty
?
Your namespace can be any capitalization you desire. I personally do all caps as an indicator that it is a namespace, but that's just my own personal style and would probably seem too much if the namespace name was long and multiple words. The examples you show are fine (assuming that you aren't literally using "MyNamespace", but have selected your own name).
And, the idea of a namespace is to pick something that's very likely to be unique to your application and therefore unlikely to conflict with something that occurs elsewhere in nature.
While you can create your namespace arbitrarily regarding to capitalization and cases, I tend to follow the conventions (all in lowercase) used in Java. e.g. com.example.utils
, com.example.core
, etc. Then having the class and function names capitalized at will. e.g. com.example.utils.TwistedBase64 = function(){ ... };
精彩评论