What are the arguments of jQuery Deferred callbacks?
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.)
精彩评论