setTimeout按照给定顺序执行
var arr = [1000, 3000, 500]; function next() { var d = jQuery.Deferred(), i = 0, doNext = function () { if (i < arr.length) { console.log(arr[i] + "-------------" + arr[i] * Math.random()); i++; setTimeout(doNext, arr[i]); } else { d.resolve(); } }; setTimeout(doNext, arr[i]); return d.promise(); } next().then(function(){ console.log("OK! its finish."); });