I have to set up a new JavaScript library for a big project, which isn't Object Oriented yet. So I built a small file to test some needs. The result is the following:
var Module =
{
Config: (function()
{
//- private members
var _systemName = 'mySystem',
_version = '1.1.4';
//- private methods
//...
//- public methods
var api =
{
getSystemInfo: function()
{
return "system: '"+_systemName+"' @ version "+_version;
}
};
return api;
})(),
Dialog:
{
_: (function(){
$(document).ready(function()
{
$('.showDialog').on('click',function()
{
var obj = {
element: this,
foo: 'foo',
bar: 'bar',
target: $('#title')
};
Module.Dialog.setParam(obj);
Module.Dialog.show();
})
});
})(),
setParam: function(config)
{
console.log('config set for dialog box');
console.log(config);
},
show: function()
{
console.log('dialogbox show | '+Module.Config.getSystemInfo());
},
close: function()
{
console.log('dialogbox close');
}
},
Savescreen:
{
setParam: function(config,foo)
{
console.log('config set for savescreen');
},
show: function()
{
console.log('savescreen show | '+Module.Config.getSystemInfo());
}
}
}
Goals:
- access via Module.Object.Function()
- no instantiation via keyword new
- private members and methods (in config section or event-listner)
- easy structured and object orientated
- each section must have its own scope (section = savescreen, config,
dialogbox, etc)
- each section should hold its event-listner
Please let me know, what you think about this structure! Thank you all!