I'm trying to follow some javascript lessons where there is an implementation of Deferred. This is the core of the code
getData = function (options) {
return $.Deferred(function (def) {
var results = options.results;
getFunction({
success: function (smt) {
results("test");
def.resolve(results);
debugger;
},
error: function (response) {
def.reject();
}
});
}).promise();
},
Now the question is.. when i call this function from outside like:
$.when(somthing.getData(options)).
done(alert(options.results));
debugger;
It happens that FIRSTLY reach the debugger outside the $.when call, and THEN touch the one inside callback SUCCESS function inside the Deferred object...
I don't get it.. shouldn't be the promise done only when def.resolve(results) is reached?...