DEV Community

Discussion on: Callback hell OR try catch hell (tower of terror)

Collapse
 
sargalias profile image
Spyros Argalias

I agree. Also, if your next function happens to depend on results from the previous function, you can chain them without nesting:

function getAreas() {}
function getTowns(areas) {}
function getCities(towns) {}
function getCountries(cities) {}

getAreas()
  .then(getTowns)
  .then(getCities)
  .catch(handleError);

// or inline
getAreas()
  .then(function getTowns(areas) {})
  .then(function getCities(towns) {})
  .then(function getCountries(cities) {})
  .catch(function handleError() {});
Enter fullscreen mode Exit fullscreen mode

Nice article overall though, keep it up :).

Collapse
 
ovi profile image
Muhammad Ovi

Yes, this would be a good approach too :)