Suggerimenti

Per scrivere codice che non invecchia mai, è raccomandato aggiungere il prefisso (o il suffisso) a tutto ciò che va nel namespace globale con un infrequente prefisso (o suffisso) di 3-4 lettere separato con una sottolineatura. Si raccomanda che al fine di evitare collisioni dei namespace con altro codice dello spazio utente che i progetti ricerchino prefissi (o suffissi) esistenti utilizzati in altri progetti e pubblicizzare il loro prefisso scelto (o suffisso) in modo appropriato. Esempio:

  • MyPx_someFunc()

  • Foo_Date

  • $asdf_dbh

add a note add a note

User Contributed Notes 4 notes

up
27
willian at gt44 dot com
11 years ago
I don't think it makes sense nowadays. We have namespaces now!
up
1
kanone at rogers dot com
10 years ago
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.
up
1
mestresan AT gmail DOT com
9 years ago
Even though nowadays we do have namespaces, for the cases in which the user chooses to not use namespaces theses tips should be followed.
up
1
earnie at users dot sourceforge dot net
10 years ago
@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.
To Top