Ask HN: Is callback hell exaggerated?
11 pointsby tonyle17 comments
1. Write some JS code in chrome and verify expected behaviour.
2. Add a debugger statement.
3. When the debugger pops up, go down a few frames and add debug point.
4. Right click the frame and select restart.
5. In the new break point, write some code in the console to modify the state.
6. When you step through the code, it now does something else.
Now imagine if the language allow you to do this programmatically in the code by passing the frame around as an argument similar to functions. var state={};
function logic(step,err,data){
if(!step){
connectToDb("somedatabase",logic.bind(state,1))
}
if(step==1){
if(err) callback("error1")
state.dbInstance=data
state.dbInstance.query("someQuery",logic.bind(state,2))
}
if(step==2){
if(err) callback("error2")
csvExporter(data,logic.bind(state,3))
}
if(step==3){
if(err) callback("error3")
callback(data)
}
}
logic()
}