17

if ( condition ) {
callback(data)
}
callback(error)

--is a lot different than--

if ( condition ) {
callback(data)
} else {
callback(error)
}

callbacks are not return statements 🀦‍♂️

Comments
  • 1
    I'm sick of seeing this.

    I mostly work with PL/SQL, and I cant count the times I see something like that.

    Or ifs checking if a error message is returned, but you have a exception catching that and exiting the function
  • 7
    What if the success statement throws a success exception?

    Checkmate atheists
  • 2
    @alexbrooklyn that would’ve saved me two hours of debugging. I’m okay with that today.
  • 1
    How about

    return callback(data)
  • 0
    @neel-basu that was the point of the rant :p
  • 0
    Callback && callback(data || error);

    How about that?
    Or use promises? :p
  • 0
    @bashleigh I'm stuck passing this callback function to a 3rd party library. I'm getting ready to just copy and paste the parts of the library I need into our own codebase and refactor it the right way.
  • 0
    @devphobe do it. I dare you πŸ˜‚πŸ˜‚
  • 0
    Oh really?
Add Comment