©
Dokumen ini menggunakan Manual laman web PHP Cina Lepaskan
要写出能经受住时间考验的代码,建议给任何进入全局命名空间的符号都加上一个不常见的 3-4 字母的前缀(或后缀),中间用下划线分开。为了避免与其它用户空间代码出现命名空间冲突,建议先研究一下其它项目中已有的前缀(或后缀)并适当地公布出来。示例如下:
MyPx_someFunc()
Foo_Date
$asdf_dbh
[#1] mestresan AT gmail DOT com [2014-09-21 02:48:24]
Even though nowadays we do have namespaces, for the cases in which the user chooses to not use namespaces theses tips should be followed.
[#2] kanone at rogers dot com [2014-06-07 18:10:36]
The javascript community has developed a strong cultural bias against adding anything to the global namespace. (See e.g. Addy Osmani's article on Essential JavaScript Namespacing Patterns .) Namespaces have been available in JS for many years and are ubiquitous. There is also a great deal of freely available tutorial material for the interested reader.
[#3] earnie at users dot sourceforge dot net [2014-01-30 15:46:18]
@willian at gt44 dot com: What about clashes of the namespace? It is still good advice to check for previously used names before assigning anything to the global namespace.
[#4] willian at gt44 dot com [2013-07-19 16:31:54]
I don't think it makes sense nowadays. We have namespaces now!