vendredi 13 février 2015

How to pass parameters from one deferred to the next with Javascript



Extremely simplified I have the following situation:



function fxRun() {
dtStep1().then(dtStep2);
}


with:



function dtStep1() {
var dfd = $.Deferred(function () {
setTimeout(function () {
var arr = ["x","y"];
dfd.resolve();
}, 2000);
});
return dfd.promise();
}

function dtStep2() {
var dfd = $.Deferred(function () {
setTimeout(function () {
//want to use arr here!
dfd.resolve();
}, 2000);
});
return dfd.promise();
}


How do I pass variable arr that is assigned in dtStep1() to dtStep2() so I will be able to use it there? Thanks in advance!!!








0 commentaires:

Enregistrer un commentaire