function Queue() {
this.data = [];
}
Queue.prototype = {
processTime: 20,
add: function (fn, params, context) {
this.data.push({
fn: fn,
params: params,
context: context
});
},
start: function () {
var that = this;
setTimeout(function () {
that.process();
}, this.processTime);
},
process: function () {
var d = this.data.shift();
if (!d) return;
d.fn.apply(d.context, d.params);
d = null;
this.start();
}
}
var a=11,b=22;
var q = new Queue();
q.add(function (a,b) {
console.log(1+':'+a+b);
},[a,b]);
q.add(function () {
console.log(2);
});
q.add(function () {
console.log(3);
});
q.start();