I think I know the answer but... is there any way to prevent a global variable from being modified by later-executing ? I know global variables ar
Choose a variable name which is unlikely to be overwritten by accident and trust the programmer to not do stupid things. JavaScript is not Java, so don't pretend it was.
Also, if what you really want to do is namespacing, use a self-executing function literal:
var myLibName = (function() {
var aPrivateVar;
function aPrivateFunction() {}
function accessorForPrivateVar() {
return aPrivateVar;
}
// public interface:
return {
getPrivateVar : accessorForPrivateVar
}
})();