开发者

Javascript namespace conventions [closed]

开发者 https://www.devze.com 2023-03-19 13:38 出处:网络
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references,or expertise, but this question will likely solicit debate, a
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 11 years ago.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消