admin管理员组文章数量:1277334
I have been using namespaces to package my JavaScript code. In some of the examples that I have read, all caps have been used for the global name. For example: MYAPPLICATIONNAME.module.function
Is using all capitals the best practice since it seperates the vars in the global namespace, or is it just more confusing?
I have been using namespaces to package my JavaScript code. In some of the examples that I have read, all caps have been used for the global name. For example: MYAPPLICATIONNAME.module.function
Is using all capitals the best practice since it seperates the vars in the global namespace, or is it just more confusing?
Share Improve this question asked Nov 22, 2010 at 16:48 rsidebrsideb 82910 silver badges18 bronze badges 05 Answers
Reset to default 7I think it is a good practice to use all caps to represent global variables, see: http://javascript.crockford./code.html
YUI is one of the example, e.g. YAHOO or YUI
The most important thing about standard practices is that you pick one and stick to it. In some cases, the standard practice is, well, fairly standard. Such as using all caps for constants in languages that support them. I have never encountered a namespacing standard practice for JavaScript.
I would suggest picking one that makes the most sense to you, and sticking with it. Maybe take a look at one of your favorite JS libraries, see what they do.
No, I don't believe so (quick tutorial). I would find it more confusing, personally. lowerCamelCase or UpperCamelCase is standard Java/Javascript convention.
Caps are usually used for constants. For example,
var MAX_LENGTH = 5;
Edit: Now that I look back at that link again, I see that the author did in fact use all caps in his namespace. But some do not. Again, I personally find it confusing and would only consider doing it if I was creating an immutable singleton. But even then, there are probably better ways.
Nope that would be a preference. Personally I use camelCase.
I've used ALL CAP variable for constants, but not namespacing.
My experience is Java-style code formatting.
本文标签: Is it standard practice to use all caps for a JavaScript NamespaceStack Overflow
版权声明:本文标题:Is it standard practice to use all caps for a JavaScript Namespace? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741261848a2367769.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论