title: JavaScript WebSocket replace reference with new socket
body: <p>I'm trying to reconnect a websocket automatically with a function.
  I want it to keep the same variable name, but i'm having some issues.
  here is the function I'm using</p>
  
  <pre><code>function reconnect(obj){
      try{
          obj=new WebSocket(obj.url);
          }
       except{
          setTimeout(reconnect,5000,obj);
      }
  }
  
  mysocket=new Websocket(myurl);
  mysocket.close()
  reconnect(mysocket)
  </code></pre>
  
  <p>After the reconnect function runs successfully but <code>mysocket</code> is still referenced to the old closed <code>Websocket</code>.  I'm not sure how to transfer to new <code>Websocket</code> object to the old variable.  </p>