I'm attempting to execute a second query once the first query has been resolved by using the following code:
const task1 = nextQuery => $.get('1.json', data => nextQuery());
const task2 = nextQuery => $.get('2.json', data => nextQuery());
const task3 = nextQuery => $.get('3.json', data => nextQuery());
const task4 = nextQuery => $.get('4.json', data => nextQuery());
const tasks = [task1, task2, task3, task4];
const tasksWithArgs = tasks.map((taskFn, index, arr) => {
const followingTask = arr[index + 1];
if (!followingTask) {
return;
}
return taskFn.bind(taskFn, followingTask);
});
tasksWithArgs[0]();
Despite successful requests to 1.json and 2.json, I am encountering a TypeError: nextQuery is not a function. It seems that fn2 is not receiving fn3 as an argument. Can you provide an explanation of how this code operates?