All my models and support modules are name-spaced. Currently I initialize them like this. I call initAll() on some sort of onload.
MC stands for Model-Controller and Su for Support.
/**
** initAll
*/
MC.initAll = function() {
MC.MATweet.init();
MC.MABAdder.init();
MC.MASettings.init();
MC.MUserTry.init();
MC.MUserNew.init();
MC.MUserExist.init();
Su.UserOut.init();
Su.Media.init();
}
Obviously, each has it’s own init() function. I plan on updating this to use hasOwnProperty to check for the init property and from there, if it exists call it. This would make this function a loop basically…which checks the namespace.
Are there other ways…to initialize models. Is this a good way for a light-weight application?
One way is to loop though all your models like this, and in each model check for the property init. If it is there call it. This makes initialization automatic…you just have to define it in each model.