I'm currently using the following pattern to create namespaces and singleton objects in Javascript:
var Namespace = function () {
var priv = {
privateVar1: '',
privateVar2: '',
privateFunction1: function () {
//do stuff
[...]
},
[...]
};
var pub = {
publicVar1: '',
publicFunction1: function () {
//do stuff with private functions and variables
priv.privateVar1 = priv.privateFunction1(pub.publicVar1);
[...]
},
[...]
};
return pub;
}();
I hope you get the idea. Is there a way to create namespaces that you think is cleaner or better (explain why)?