Tengo la siguiente clase JS. Básicamente estoy envolviendo el objeto Websocket dentro de una clase
class MyClass { // Main constructor constructor() { this.ws = null; this.ConnectionState = false; } // Heart beat function #heartbeat() { // Do some stuff } // Initialization of the websocket Init() { this.ws = new WebSocket("some url..." ); this.ws.onopen = function (event) { this.ConnectionState = true; this.#heartbeat(); // << The error is raised here } } }Cuando ejecuto el método Init() , aparece el error: TypeError no detectado: el objeto debe ser una instancia de la clase MyClass en WebSocket.Init.ws.onopen
Esto sucede en la fila: this.#heartbeat();
¿Alguien puede ayudar con eso por favor?
Gracias