最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery .then() call two functions - Stack Overflow

programmeradmin8浏览0评论

If I have three functions a, b, and c:

function a() {
    var deferred = new $.Deferred();
    // stuff -- resolve deferred once async method is plete
    return deferred.promise();
}

a().then(b)

This works fine, but how could I also call function c after a is finished?

Something like:

a().then(b,c)

If I have three functions a, b, and c:

function a() {
    var deferred = new $.Deferred();
    // stuff -- resolve deferred once async method is plete
    return deferred.promise();
}

a().then(b)

This works fine, but how could I also call function c after a is finished?

Something like:

a().then(b,c)

Share Improve this question asked Jun 18, 2015 at 9:59 frostyfrosty 2,8516 gold badges42 silver badges66 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

Mostly in all cases, you could use done():

a().done(b, c);

You can call the both function at the same time using as callback function.

a().then(function () {
    b();
    c();
});

You can chain them

a().then(b).then(c)

Demo: Fiddle

发布评论

评论列表(0)

  1. 暂无评论