Put everything in a namespace. This not only avoids collisions with other people’s scripts but also organize your objects into groups that make sense. Lets start namespacing !
// Using abbreviation of DotToString = DTS
if (typeof DTS == "undefined")
{
var DTS = {};
}
// Make a function for creating namespaces
DTS.namespace = function() {
var a=arguments, o=null, i, j, d;
for (i=0; i<a.length; i=i+1) {
d=a[i].split(".");
o=DTS;
// DTS is implied, so it is ignored if it is included
for (j=(d[0] == "DTS") ? 1 : 0; j<d.length; j=j+1) {
o[d[j]]=o[d[j]] || {};
o=o[d[j]];
}
}
return o;
};
and thats all
Now you can create your own namespaces like this:
// We can mention our top level namespace
DTS.namespace("DTS.UI.Example");
// or we can just skip top level namespace
DTS.namespace("UI.widgets");
// or we can have a hybrid case
DTS.namespace("DTS.UI.Example", "UI.widgets");



Great article. Here is an article on how to use it with the jQuery object. In other words namespasing with the jQuery http://jquery-howto.blogspot.com/2009/01/namespace-your-javascript-function-and.html