Javascript naming conventions

I have namespaced my javascript.

Are there any conventions related to capitalization and namespace casing?

Is it good to have a namespace in the form of MyNamespace , so when I access a property or function, I use MyNamespace.myProperty ?

+6
source share
2 answers

Your namespace can be any desired capitalization. I personally do all the caps as an indicator that this is a namespace, but this is just my personal style and probably too much if the namespace name would be long and a few words. The examples you show are great (unless you use "MyNamespace" literally, but choose your name).

And the idea of ​​the namespace is to choose something that is very likely to be unique to your application, and therefore unlikely to conflict with what happens in other places.

+2
source

As long as you arbitrarily create your namespace in terms of capitalization and cases, I tend to follow the conventions (all lowercase) used in Java. e.g. com.example.utils , com.example.core , etc. Then, using class and function names, capital letters are uppercase. for example com.example.utils.TwistedBase64 = function(){ ... };

+1
source

Source: https://habr.com/ru/post/892604/


All Articles