If we want to create a singleton object, i.e. there can only every be one instance of it that is referenced by a global variable, in JavaScript it is very easy.  We simply declare the class function inline, returning a new object with the public methods and properties on, directly followed by () parenthesis and assign it to our global variable.

If you want to create private methods and functions then you should be able to see the similarities of this and the JavaScript Class Patterns article.

   1: var MySingleton = function(){
   2:     return {
   3:         // variables and methods 
   4:         id : 1,
   5:  
   6:         test : function()
   7:         {
   8:             return this.id;
   9:         }
  10:     }
  11: }();