2 个回答

这代码看得我很感动,所以我打出了GG,你直接在控制台输入下面代码就可以看到结果了。。。

function async(arr){
    if( Object.prototype.toString.call(arr) != "[object Array]" ){
        return false;
    }
    var target = arr.shift();
    if(typeof target != "function"){
        return false;
    }
    target(function(){
        async(arr);
    });
}

var one = function(callback){
    setTimeout(function(){
        console.log("first");
        callback();
    },200);
};

var two = function(callback){
    setTimeout(function(){
        console.log("second");
        callback();
    },100);
};

async([one,two]);
async([one,two,two,one,two]);
新手上路,请多包涵

我很想问,,异步总得有个url吧,你让url写成函数。。。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题