(function ($) { var a = ['test1', 'test2', 'test3', 'test4']; recursive(3, 'test').done(function (result) { console.log(result); }); function get(id) { var dfd = $.Deferred(); setTimeout(function () { dfd.resolve(a[id]); }, 1000); return dfd.promise(); } function recursive(n, result) { var dfd = $.Deferred(); if (n == 0) { get(n).done(function (result1) { dfd.resolve(result1 + result); }); } else { get(n).done(function (result2) { recursive(n, result2).done(function (result3) { dfd.resolve(result3 + result); }) }) } n--; return dfd.promise(); } })(jQuery)
基于jquery 1.6+
结果:
test1test2test3test4test
转载于:https://www.cnblogs.com/LiuXianBlog/p/3579814.html