admin管理员组

文章数量:1394988

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

本文标签: javascriptjQuery then() call two functionsStack Overflow