开发者

What are the arguments of jQuery Deferred callbacks?

开发者 https://www.devze.com 2023-03-01 09:21 出处:网络
In jQuery, deferred.then adds handlers to be called when the Deferred object is resolved or rejected.

In jQuery, deferred.then adds handlers to be called when the Deferred object is resolved or rejected.

deferred开发者_C百科.then( doneCallbacks, failCallbacks )
  • doneCallbacks — A function, or array of functions, called when the Deferred is resolved.
  • failCallbacks — A function, or array of functions, called when the Deferred is rejected.

What are arguments of these 'done' and 'fail' callback functions in the following example?

Does it depend on the type of Deferred object? For example:

$.when({testing: 123})
  .then(function(x){ ... }); 

$.when($.getJSON('foo'))
  .then(function(x){ ... });

will have different values for 'x'?


Done fallbacks and fail fallbacks are invoked by the creator of the Deferred calling resolveWith() and rejectWith(), respectively; the two arguments these functions take are passed to the callback. So it depends entirely on the type of the function that created the Deferred object. (Context is usually but not necessarily the Deferred object itself.)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号