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 I use MyNamespace.myProperty
?
Naming Convention for Variables JavaScript variable names are case-sensitive. Lowercase and uppercase letters are distinct. For example, you can define three unique variables to store a dog name, as follows. However, the most recommended way to declare JavaScript variables is with camel case variable names.
In JavaScript, closures are created every time a function is created, at function creation time.
camelCase is used by JavaScript itself, by jQuery, and other JavaScript libraries. Do not start names with a $ sign. It will put you in conflict with many JavaScript library names.
Let's have a look at another example. In the above program, the calculate() function takes a single argument x and returns the function definition of the multiply() function. The multiply() function takes a single argument y and returns x * y . Both multiply3 and multiply4 are closures.
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(){ ... };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With