Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 I use MyNamespace.myProperty?

like image 800
amateur Avatar asked Jul 12 '11 17:07

amateur


People also ask

What are bad naming conventions in JavaScript?

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.

Are there closures in JavaScript?

In JavaScript, closures are created every time a function is created, at function creation time.

Is JavaScript camelCase or Snake_case?

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.

What are the examples of closures in JavaScript?

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.


2 Answers

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.

like image 82
jfriend00 Avatar answered Oct 16 '22 10:10

jfriend00


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(){ ... };

like image 26
shinkou Avatar answered Oct 16 '22 10:10

shinkou