title: How to access class variables from inner prototype - javascript
body: <p>I might not be clear with my title of the question. Sorry for that.</p>
  
  <p>Here is what I wanted to do. </p>
  
  <p>I'm trying to use prototyping pattern in javascript. I created a class as following.</p>
  
  <pre><code>var MyClass = null;
  (function() {
      MyClass = function() {
          this.clsVar = "I'm inside constructor";
      };
  
      MyClass.prototype = {
          constructor: MyClass,
          myFunc1: function() {
              console.log("I'm func1 accessing constructor variable : " + this.clsVar);
          },
          nested: {
              myFunc2: function() {
                  console.log("I'm func2 accessing constructor variable : " + this.clsVar); // I know, this will never point to the class scope
              }
          }
      }
  }())
  </code></pre>
  
  <p>I'm creating an object.</p>
  
  <pre><code>var my = new MyClass();
  
  my.myFunc1(); // which prints "I'm func1 accessing constructor variable : I'm inside constructor" 
  
  my.nested.myFunc1(); // as expected, it prints "I'm func2 accessing constructor variable : undefined
  </code></pre>
  
  <p>All I am trying to do is, I should be able to access <code>clsVar</code> from <code>nested.myFunc2</code></p>
  
  <p>is that possible.? Any help is greatly appreciated and needed. 
  Thanks.</p>