Reputation: 26538
I work for a company which has multiple websites, all of sites somehow share some kind of common code. Recently I am working on a project to revamp the UI of a particular website, here are some the problems I have faced:
I started to "web parts" concept to pull content from different page via ajax. However I have name/id clashes. Eg. the main page has a tag <div id="tmp">
, and the web part that I am pulling over also has a tag <div id="tmp">
There are more than 1 guy writing javascripts, sometimes writing library code, sometimes writing page specific code. And we have naming clashes...
I was thinking to standardize the naming convention to something like this: global variables will have "global_" prefixes, page specific code should have "[pagename]_" prefixes(however, we will see a lot of clashes for index.html)
Hence I am asking if anyone has a pretty solid standardization to share with?
Thanks in advance.
James
Upvotes: 0
Views: 332
Reputation: 19998
I would suggest that if you were starting for scratch then putting all of your global stuff into a single name space like jQuery do with their $
symbol would be a good idea.
That way individual developers know they don't have to worry about hiding a global variable and visa versa for the global code.
You were essentially suggesting providing separate name spaces for global and page code with your name prefixes. However that would quickly become irritating and hard to modify.
You could even have name spaces for each page as you suggested regarding the variable naming scheme.
Upvotes: 1