$.when配合带有ajax的函数

app = {
    init(){
        $.when(
            this.loadXXX(),
            this.loadYYY()
        )
    },
    loadXXX(){
        let dtd = $.Deferred();
        $.ajax({
            ...,
            success:function(){
                dtd.resolve();
            }
        });
        return dtd;
    },
    loadYYY(){
        let date = "";
        return this.loadYYYHelper(date);
    },
    loadYYYHelper(){
        let dtd = $.Deferred();
        $.ajax({
            ...,
            success:function(){
                dtd.resolve();
            }
        });
        return dtd;
    }
}

其他信息自行百度

你可能感兴趣的:(JS)