Correct way to handle .then continuation
I have a .then continuation that should either call another asynchronous function or not do anything. What is the correct way to write the function? Here it is:
function loadCategories(shortDescription, categoryId, index) {
return categoryService.loadChildCategories(shortDescription, categoryId, index)
.then(function (result) {
return categoryService.prefetchChildren(shortDescription, result, index + 1);
});
}
I want to call prefetchChildren only if index < 4. Question is what do I return if index >= 4 to make the function chainable with .then?