0

I have socket connection, i am trying to subscribe to this onMessage function from different class, so that i can get the messages in that particular class, but i am not able to make call to test() in side the processTicks function in below code snippet. Please help. Thanks

class SocketClient {
  this._ws.onmessage = (msg) => {
    for (var i = this._handlers.length - 1; i >= 0; i--) {
      this._handlers[i](msg);
    }
  };
  setHandler(callback) {
    this._handlers.push(callback)
  }
}

class SomeOtherClass {

  test() {

  }


  processTicks(ticks) {
    try {
      this.test() //this is not working
      // how do i get the correct this here,
      // so that i can call some function inside this class

    } catch (err) {
      console.log(err)
    }
  }

  registerListner() {
    socketClient.setHandler(this.processTicks);
  }
}
spender
  • 112,247
  • 30
  • 221
  • 334
Dipesh Gupta
  • 128
  • 1
  • 2
  • 10

0 Answers0