日期:2014-05-16 浏览次数:20437 次
var ExecQueue = function() { this.queue = []; }; ExecQueue.prototype = { add : function(fn, args, time) { this.queue.push( { fn : fn, args : args, time : time }); }, exec : function() { var delay = 0; for ( var i = 0; i < this.queue.length; i++) { var _this=this; var f=function(idx){ return function(){ _this.queue[idx].fn.apply(_this,_this.queue[idx].args); } }(i); setTimeout(f, delay); delay += this.queue[i].time; } } } function a(){ alert('a'); } function b(i){ alert('b'+i); } function c(i,j){ alert('c'+i+j); } var execqueue=new ExecQueue(); execqueue.add(a,[],5000); execqueue.add(b,['i'],5000); execqueue.add(c,['c1','c2'],5000); execqueue.add(c,['c3','c4'],2000); execqueue.exec();