Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="[add your bin description]">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
const urls = ['url1', 'url2', 'url3'];
function fakeFetch(url, params = '-') {
  // этот вывод в консоль покажет порядок вызовов с их входящими параметрами
  console.log(`fakeFetch to: ${url} with params: ${params}`);
  return new Promise(resolve => {
    setTimeout(() => resolve(`${url} is DONE`), 1000);
  })
};
function recursionWay(callback) {  
    const recursion = (arr = [], promise = Promise.resolve()) => {
        if (!arr.length) { 
            return promise;
        }
        const [url, ...restUrls] = arr;
        return promise
            .then(res => recursion(restUrls, fakeFetch(url, res)));
    }
    recursion(urls)
        .then(result => callback(result));
}
recursionWay(result => console.log(`result: ${result}`))
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
andr213pro
0viewers