Batch.prototype.execute = functionexecute() { var i; var functions = this._functions; var length = this._remaining = functions.length; this._results = []; for (i = 0; i < length; i += 1) { functions[i](this); } };
var i; var length = urls.length; var batchFunctions = [];
// 创建需要被batch执行的函数数组 for (i = 0; i < length; i += 1) { batchFunctions.push(function (batch) { $.ajax.get(urls[i], function (response) { batch.done(response); }); }); }
var myBatch = new Batch(batchFunctions, function (results) { //返回各个函数的结果数组 });