I am trying to implement this way to structure my jquery binds, it worked perfect.
I just have one question:
In the sample in the article he put all the views in one namespace called SITENAME, and like that all views should exist in one .js file, how can I put the views in different .js files?
for example:
To put common view in common.js file and users view in users.js
Namespace
SITENAMEis just a JavaScript object.If you have code like this:
You can change it to:
As you can see now the
example1andexample2objects are still defined insideSITENAME, but they are separated from the definition ofSITENAMEobject itself.So in your case you need to create your “namespace” object first (e.g. create app.js which will contain also some configuration stuff) and then you create separate .js files that will define own properties on already existing
SITENAMEobject.Example:
HTML:
app.js (insert here common functionality, configuration, etc):
example1.js:
example2.js: