Vote count:
0
I have created following javascript code:
var index, _i;
var dfd = new $.Deferred();
dfd.resolve();
for (index = _i = 0; _i < 10; index = ++_i) {
$.when($, dfd).done(function() {
console.log('ping');
promise = (function(index) {
setTimeout(function() {
console.log('pong');
dfd.resolve();
}, 3000);
dfd.reject();
})(index);
})
}
in console I see following result
ping
ping
ping
ping
ping
ping
ping
ping
ping
ping
pong
pong
pong
pong
pong
pong
pong
pong
pong
pong
But I want to achieve
ping
pong
ping
pong
....
Where do I wrong and how to rewrite code acording my desired behavour?
asked 10 mins ago
ping pong behaviour using deffered
Aucun commentaire:
Enregistrer un commentaire