JavaScript Namespaces

Object Encapsulation
if (typeof My == 'undefined')
  My = {};
if (typeof My.Namespace == 'undefined')
  My.Namespace = {};
  
Scoped Closure
(function(){

    var private-var=...;
    
    this.foo=function () {..}
    
    this.Bar = {}

    this.Bar.prototype.doSomething = function() {
      ...
    }

}).call(My.Namespace);