0
const req = https.request(options, (res) => {
  console.log(res);

  res.on("data", (d) => { // Same thing here
    console.log(d);
  });
});

How does this function know to fill that res parameter with the response object, and how does it do it? I could put there any function, but only in this syntax it works like this.

function callback(res) {
  console.log(res);
}

If i define a function like this, and pass it as callback to https.request it won't work as expected.

How does this thing work?

(Note that I'm testing this with a playwright test file, don't know if it can affect the situation)

Bit
  • 21
  • 7

0 Answers0