Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

197
Vistas
Callback function in node.js and socket.io

I need to fire a callback of a function at a specific time, in the index.js (at server side). My problem is that the callback seams to be able to pass only variables but not an entire function. I need to have scope on the entire socket instance to disconnect a specific socket at a specific time.

//index.js (Node.js + socketIO)

let chat = require(chat.js)
let c = new Chat

//Various socketio strings

c.on("example",function(data){
  if(socket.id === data){
     socket.disconnect()
  }
})



//chat.js

class Chat{
 events = {};

 on(event,callback){
  this.events[event] = callback
 }

 function disconnect(){
  if(this.events.example){
    this.events.example("example sockeetid")
  }
 }
}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda