SampleHere's a simple, yet incomplete implementation using this new approach (it lacks the document.ready part). It is long, to be placedyet it's modular and easily maintainable. You can even split the section codes in your base code:separate files.
Module(function (ns) {
ns.addSection = function (name, def) {
//check if namens[name] and= new def();
are what}
}(this.Module they= are:this.Module string|| and{}));
//adding functionconfig
Module.addSection('Config', function () {
//createvar ansystemName instance= of'mySystem',
the constructor version = '1.1.4',
var section = newthis;
def section.getSystemInfo = function ();
{
//add the sectionreturn tosystemName the+ module' namespace
v' + Module[name]version;
= section;}
});
Here's a simple usage for such functionality with Config:
//adding Dialog
Module.addSection('Config''Dialog', function () {
//everythingvar insection here= isthis;
private section.onDocumentReady = function () {
$('.showDialog').on('click', function () {
var systemNameobj = 'mySystem'{
element: this,
version = '1.1.4' foo: 'foo',
bar: 'bar',
target: $('#title')
};
section.setParam(obj);
//the namespace for this section.show();
is provided via "this"})
so you}
can exposesection.setParam = function (config) {
//your public interfaceconsole.log('config set for thisdialog sectionbox');
this console.getSystemInfolog(config);
}
section.show = function () {
returnconsole.log('dialogbox systemNameshow +| ' v'+version;+ Module.Config.getSystemInfo());
}
//yousection.close: mayfunction want() to{
add special functions thatconsole.log('dialogbox getclose');
fired on}
});
//Savescreen certainsection
Module.addSection('Savescreen', eventsfunction () {
//likevar forsection example,= firethis;
upon addsection.setParam or= firefunction when(config, document.readyfoo) {
//implementation depends onconsole.log('config youset for savescreen');
this}
section.onDocumentReadyshow = function () {
console.log('this'savescreen getsshow fired| on' document+ ready'Module.Config.getSystemInfo());
}
});