title: Javascript - Using Promises on Websocket?
body: <p>I am using Websockets in pure Javascript and I want to implement Promises into the Websocket functions. I don't get any errors but the Promise doesn't work.</p>
  
  <p>Using the following code I can connect succesful to the socketserver but the Promise seems to be skipped because the output of the alert is always "failed".</p>
  
  <p>Does somebody knows what the problem is in this case?
  Ps: I did the tests in the latest Google Chrome browser and the latest Mozilla Firefox browser, and I left out some basic checking/error handling for this example.</p>
  
  <pre><code>function Connect()
  {
      server = new WebSocket('mysite:1234');
  
      server.onopen = (function()
      {
          return new Promise(function(resolve, reject) 
          {
              if (true)
              {
                  resolve();
              }
              else
              {
                  reject();
              }
          });
      }).then = (function()
      {
          alert('succeeed');
      }).catch = (function()
      {
          alert('failed');
      });
  }
  </code></pre>