简体   繁体   中英

jQuery .then() call two functions

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

function a() {
    var deferred = new $.Deferred();
    // stuff -- resolve deferred once async method is complete
    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)

大多数情况下,您可以使用done()

a().done(b, c);

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

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

You can chain them

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

Demo: Fiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM