What exactly .deferred do what is its work and where and when we should use .deferred with resolve. In below function I have two .done callbacks. I want to set two different callback msg. fiddle
var deferred = $.Deferred();
deferred.done(function(value) {
alert(value);
}).done(function(id){
alert(id)
});
console.log(deferred)
deferred.resolve("hello world");
Answer
jQuery.Deferred
is the main tool of jQuery's implementation of the promise pattern.
Here are a few links, worth reading :
As for your specific need : you should use .then()
(read the docs for .done()
and .then()
).
var deferred = $.Deferred();
deferred.then(function(value) {
alert(value);
return 42;
}).then(function(id){
alert('The answer : ' + id);
});
console.log(deferred)
deferred.resolve("hello world");
No comments:
Post a Comment