My code will become a mess if I donβt start using some kind of namespace technique. I am relatively new to programming large javascript projects, but have significant experience with system programming in C ++ / java / python, etc.
Basically, I am trying to determine which one is preferable for creating javascript namespaces, as well as what are the pros / cons for each method.
For example, I could use one of the following three methods:
var proj.lib.layout = {
"centreElem":
function (elem, W, H){
},
"getAbsolutePosition":
function (elem){
}
};
OR
var proj.lib.layout = {};
(function(){
var l = proj.lib.layout;
l.centreElem = function (elem, winW, winH){
..
}
l.getAbsolutePosition = function (elem){
..
}
})();
OR
var proj.lib.layout = new function(){
function centreElem(elem, W, H){
..
}
function getAbsolutePosition(elem){
..
}
this.centreElem = centreElem;
this.getAbsolutePosition = getAbsolutePosition;
} ();
There are other ways to make this too obvious, but these were the first ones that I saw and thought. Can anyone say that there is a βbestβ technique, or at least point me to some pros and cons, from which I can evaluate what is best for me?