jquery $.when() difference between .then() and .done()

前端 未结 1 1662
北荒
北荒 2020-12-25 11:46

I am trying to understand the difference between

$.when(...).then(...)

$.when(...).done(...)

in jQuery. As far as I understood both of the

相关标签:
1条回答
  • 2020-12-25 12:32

    .done() has only success callback.

    .then() has both success and fail callbacks.

    As of jQuery 1.8, the deferred.then() method returns a new promise that can filter the status and values of a deferred through a function, replacing the now-deprecated deferred.pipe() method.

    The deferred.done() method accepts one or more arguments, all of which can be either a single function or an array of functions.

    Since deferred.done() returns the deferred object, other methods of the deferred object can be chained to this one, including additional .done() methods. When the Deferred is resolved, doneCallbacks are executed using the arguments provided to the resolve or resolveWith method call in the order they were added.

    0 讨论(0)
提交回复
热议问题