callback-hell icon indicating copy to clipboard operation
callback-hell copied to clipboard

Can you add some words on how callback arguments get set

Open rickschmoo opened this issue 10 years ago • 0 comments

Thanks for doing this!

Something which throws me whenever I look at callback code, is where the "err, response, body" arguments to postResponse come from. I feel like this is a stumbling block for many people. Thanks again!

  var name = document.querySelector('input').value
  request({
    uri: "http://example.com/upload",
    body: name,
    method: "POST"
  }, postResponse)
}

function postResponse(**err, response, body**) { // <<<<<< here
  var statusMessage = document.querySelector('.status')
  if (err) return statusMessage.value = err
  statusMessage.value = body
}
document.querySelector('form').onsubmit = formSubmit

rickschmoo avatar Feb 19 '15 05:02 rickschmoo