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

144
Views
Why is this instance of a class being converted to a regular object in JavaScript?

I am making an app with WebSockets in Node.js. In order to run certain things asynchronously, I wrapped some async code in an async function and then ran it.

However, the issue is that whenever this portion is ran, the code throws an error that call.createTransport is not a function. This function is clearly defined in the Call class and works when I call it outside of this context.

I proceeded to log the call and found that before running the async function, the call object was an instance of Call, but inside the async function it is a regular JavaScript object, with the properties but not the methods defined.

I am completely stuck on this issue. I am running Node.js 16 LTS.

(async (call, produce, consume) => {
    let sendTransport;
    if (produce) {
        sendTransport = await call.createTransport();
    }
    let receiveTransport;
    if (consume) {
        receiveTransport = await call.createTransport();
    }
    return { sendTransport, receiveTransport };
})(client.call, produce, consume).then(({ sendTransport, receiveTransport }) => {
    callClients.set(sId, {
        ...client,
        produce: true,
        sendTransport,
        receiveTransport
    });
    s.send(JSON.stringify({
        type: CallEventType.TRANSPORT,
        data: {
            sendTransport,
            receiveTransport
        }
    }));
});
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!