title: Javascript: Assigning a Private Method to Private Variable
body: <p>So I'm having some JavaScript issues.  I'm not a pro, and don't understand why this does not work.  All I am trying to do is assign my private variable to the return value of a private function.  If I set var xxx=function name() will it execute the function when I reference xxx.  Here is my code.  Note - var username=getsessionuser(); below.</p>
  
  <pre><code>//Namespace
  var SESSIONCONTROLS=SESSIONCONTROLS || {};
  SESSIONCONTROLS.APP=SESSIONCONTROLS.APP || {};
  
  
  SESSIONCONTROLS.APP.User = (function () {
  // defined within the local scope
  
  //Private Variable
  var username=getsessionuser();
  
  //Privatemethod
  var getsessionuser=function(){var mname='My Name'; return mname;}  
  
  //Private Property &amp; Method Example
  var privateMethod1 = function () { alert("private method 1"); }
  var privateMethod2 = function () { alert("private method 2");}
  
  var privateProperty1 = 'foobar';
  return {        
      //Public Method &amp; Nested Namespace examples
      //Public Methods
      publicMethod1: privateMethod1,
      //nested namespace with public properties
      properties:{
          publicProperty1: privateProperty1,
          sessionname:username
      },
      //another nested namespace
      utils:{
          publicMethod2: privateMethod2
      }
    }
  })();
  </code></pre>
  
  <p>This is how its called in another routine.</p>
  
  <pre><code>var name=SESSIONCONTROLS.APP.User.properties.sessionname;
  alert(name);    
  </code></pre>
  
  <p>Why doesn't this work?</p>