title: javascript websocket onmessage event.data
body: <p>Using JavaScript WebSocket how to pass <code>event.data</code> out <code>onMessage</code> function? </p>
  
  <pre><code>var eventData = EventRequest("text");
  
  
    ..... codes .....
  
  
  EventRequest = function (text)
  {
     var socket = new WebSocket ('ws://localhost:8080/');
     websocket.onopen = function(evt) { onOpen(evt); };
     websocket.onmessage = function(evt) { onMessage(evt); };
  
  function onOpen (evt)
  {
     socket.send("text");
  }
  
  function onMessage (evt)
  {
     alert (evt.data);
     return evt.data;
  }
  };
  </code></pre>
  
  <p>I tried different ways to pass evt.data out, but I have not been able to. I can see the correct <code>evt.data</code> data. I just can not pass the data out of <code>onMessage</code> function. </p>
  
  <p>I tried</p>
  
  <pre><code>function wcConnection (){
     this.dataInput = '';
  }
  </code></pre>
  
  <p>Inside <code>onMessage</code> function, I added</p>
  
  <pre><code>function onMessage (evt)
  {
     alert (evt.data);
     this.dataInput = evt.data;
  }
  </code></pre>
  
  <p>Any help would be appreciated.</p>