constructor(url, protocols = [], options = {}) {
    this._url = url;
    this._protocols = protocols;
    this._options = Object.assign({}, defaultOptions, options);
    this._reconnectAttempts = 0;
    this.readyState = ReconnectableWebSocket.CONNECTING;
    this.wasClean = false;

    if (typeof this._options.debug === 'function') {
      this._debug = this._options.debug;
    } else if (this._options.debug) {
      this._debug = console.log.bind(console);
    } else {
      this._debug = function() {};
    }

    if (this._options.automaticOpen) this.open();
  }
This code copied from https://github.com/vmakhaev/reconnectable-websocket
for minor specific changes.

Author Vladimir Makhaev.