Oh, now I see - this code is using anonymous function and storing the result in the variable `webSocketUrl`. Ignore the first part of my comment.

How about simplifying the implementation into this?

```js
var webSocketUrl = function() {
  var a = document.createElement('a');
  // browser will resolve this relative path to an absolute one
  a.href = 'ws';
  // forward parameters like port
  a.search = window.location.search;
  a.protocol = // etc.
  return a.href;
}();
```