📜  嵌套回调 javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:42.002000             🧑  作者: Mango

代码示例1
//nested callback eg, with conditional check for url

function download3(urls, success, fail) {
            setTimeout(() => {
                console.log(`Downloading ${urls} ...`);
                var err = urls.length === 0 || !urls;
                err ? fail(urls) : success(urls);
            }, 3000);
        }

        const url_a = 'https://www.javascripttutorial.net/pic1.jpg';
        const url_b = 'https://www.javascripttutorial.net/pic2.jpg';
        const url_c = '';

        download3(url_a, function(picture_a) {
            console.log(`Processing ${picture_a}`);

              download3(url_b, function(picture_b) {
                  console.log(`Processing ${picture_b}`);

                    download3(url_c, function(picture_c) {
                        console.log(`Processing ${picture_c}`);
                    }, function(picture_a){
                        console.log(`Handling error...`)});

              },function(picture_b){
                      console.log(`Handling error...`)});

        },function(picture_c){
                    console.log(`Handling error...`)});