I am trying to reorganize my Javascript into JS files and clear out my js from my html... The way I see if is the following.... I would really like some input or any documentation/information confirming my plans - a little uncertain.
Basically if I have a Home.htm file then I will have a home.js file also, notice they are named the same. The home.js will be like the bootstrapper for that page and will assign events (onclick
etc)...
I was planning on doing this with all files i.e. login.htm > login.js ...
I was also thinking about have a global.js file which will be included in EVERY page that contains items that are needed in every file..
I also plan on having other js files which I plan o开发者_JS百科n producing in a namespace so that my bootstrapper files can call classes in that namespace to do things like date manipulation etc.. I know JS is not a true OOP language but i have some helper js which allow to create namespaces and better class structures.
Does anyone have a better idea? Am completely going in the wrong or right direction?
I would really like some input, I am trying to separate all my js into separate files but I don't want to repeat myself so I thought of creating those bootstrapper files to take care of everything for the page..
Depending on how you go about it, I think the idea itself is quite reasonable. Namespacing your JS code in an OOP-like fashion is a good idea, and many libraries such as YUI and Dojo already do it.
精彩评论