title: javascript class variable scope in callback function
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/80084/in-javascript-why-is-the-this-operator-inconsistent">In Javascript, why is the &ldquo;this&rdquo; operator inconsistent?</a>  </p>
  </blockquote>
  
  
  
  <p>I have the following class:</p>
  
  <pre><code>function Chat(some, nick, url) {
      this.socket = null;
      this.Nickname = nick;
      this.Url = url;
  
      this.Connect = function () {
          socket = io.connect(this.Url);
          socket.on('connect', function (data) {
              var p = this.Nickname; //this.Nickname is undefined why? 
              // how can I acess to the Nickname variable or function?
          }
      };
  }
  </code></pre>
  
  <p>How can I acces the instance variable or function from the connect callback function?</p>