Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!