我有一个如下结构,我需要按顺序执行:
var task1, task2, task3, last;
initialize = $.when(function(){ ...initializing... }).done(function(){ ..initialization completed.. });
task1 = initialize.when(function(){ ..doing task1.. }).done(function(){ ..task1 completed.. });
task2 = task1.when(function(){ ..doing task2.. }).done(function(){ ..task2 completed.. });
task3 = task2.when(function(){ ..doing task3.. }).done(function(){ ..task3 completed.. });
last = task3.when(function(){ ..doing last.. }).then(function(){ ..last completed.. });
如何用 jQuery-1.10.2 做到这一点?
考虑到上面的示例,控制台输出将是:
initializing
initialization completed
doing task1
task1 completed
doing task2
task2 completed
doing task3
task3 completed
doing last
last completed