i'm trying to run second query when first was resolved like so:
const fn1 = secondQuery => $.get('1.json', data => secondQuery());
const fn2 = secondQuery => $.get('2.json', data => secondQuery());
const fn3 = secondQuery => $.get('3.json', data => secondQuery());
const fn4 = secondQuery => $.get('4.json', data => secondQuery());
const queries = [fn1, fn2, fn3, fn4];
const queriesWithArgs = queries.map((queryFn, index, arr) => {
const nextQuery = arr[index + 1];
if (!nextQuery) {
return
}
return queryFn.bind(queryFn, nextQuery);
});
queriesWithArgs[0]();
but still getting error TypeError: secondQuery is not a function, while requests to 1.json and 2.json works fine fn2 seems to not receive fn3 as argument. Can you explain how it works ?
queryFn.bind(queryFn, nextQuery);supposed to achieve?queryFn.bind(null, nextQuery);or simply() => queryfn(nextQuery)?nullwould make more sense as the first argument tobindthere.