我是第一次使用async.js,并希望将函数数组分离成单独的函数。我有:
工作代码
async.waterfall([
function(callback)
{
var querySuccess = function (tx, result)
{
callback(null, result.rows.item(0).EventImportTime || "");
};
var queryError = function (tx, e)
{
callback("Query Error")
};
database.open();
database.query("SELECT EventImportTime FROM Contact WHERE Contact.Id = ?", [contactId], querySuccess, queryError);
},
function(lastImportTime, callback)
{
var url = "";
url += 'MobileGetvents.aspx?';
url += '&LastImportTime=';
url += lastImportTime;
url += '&Format=JSON';
callback(null, url)
},
],
function(err, result)
{
if (err)
console.log("Error Happened");
else
{
console.log(result);
getJSON(result, callback,
errorCallback)
}
})
我想要
async.waterfall([
getLastImportTime(callback) ,
buildUrl(lastImportTime, callback),
],
//callback
);
然而,当我运行此代码时,它总是返回
未捕获的ReferenceError:未定义lastImportTime
答案 0 :(得分:5)
我认为你想要这个:
var getLastImportTime = function(callback) { };
var buildUrl = function(lastImportTime, callback) { };
async.waterfall([
getLastImportTime,
buildUrl,
],
//callback
);