title: Javascript Class returns undefined
body: <p>When using this Code the function returns undefined instead of an object.</p>
  
  <pre><code>function Oauth_User_Profile() {
      this.username = "=";
      this.password = "=";
      this.refresh_token = "=";
      this.access_token = "=";
      this.request = function(url, formData, method, then) {
          var xhttp = new XMLHttpRequest();
          xhttp.onreadystatechange = function() {
              if(xhttp.readyState == 4 &amp;&amp; xhttp.status == 200)
              {
                  var j = JSON.parse(this.responseText);
                  then(j);
              }
          }
          xhttp.open(method, url); 
          xhttp.send(JSON.stringify(formData)); 
      }
  }
  
  var oauth_user_profile = Oauth_User_Profile();
  oauth_user_profile.username = "sample";
  </code></pre>
  
  <p>I've got nearly the same Code for other classes which is working fine, so I don't know why this isn't running properly</p>
  
  <p><strong>Duplicate:</strong>
  Question was marked as a duplicate for [<a href="https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call]">How do I return the response from an asynchronous call?</a>. However, I don't want to return the result of the call, I want to return an object which contains username, password, refresh_token... AND a method which can be run. I run into the exact same problem when removing the async-part:</p>
  
  <pre><code>function Oauth_User_Profile() {
   this.username = "=";
   this.password = "=";
   this.refresh_token = "=";
   this.access_token = "=";
  }
  </code></pre>
  
  <p>This still gives the error: <strong>Uncaught TypeError: Cannot set property 'username' of undefined
      at testm.html:67</strong></p>