【发布时间】:2016-09-07 18:56:14
【问题描述】:
我在两个具有相同回调函数的函数中使用async.parallel
.在第二个函数(two())中添加了第三个函数作为加法函数
function one(){
var testuser = 1;
async.parallel([onefunction, secondfunction], function(err, result){...})
}
function two(){
var testuser = 2;
async.parallel([onefunction, secondfunction, thirdfunction], function(err, result){...})
}
function onefunction(callback){....code with testuser......}
function twofunction(callback){....code with testuser......}
function thirdfunction(callback){....code with testuser......}
问:如何访问onefunction、secondfunction 和thirdfunction 中的testuser 值。
现在我得到 undefined err。我也尝试了正常的参数传递逻辑onefunction(testuser),但它不起作用。
我想在多个情况下使用onefunction、twofunction...我该怎么做?
【问题讨论】:
-
使其成为函数的参数并将其传递给它们。
-
@FelixKling 你能简单解释一下吗?你的意思是说
onefunction(testuser) -
好吧,我假设您还必须通过
callback。而且由于您必须将函数传递给async.parallel(看起来如此),它应该是callback => onefunction(testuser, callback)等 -
@PrashantTapase
secondfunction的定义在哪里?我只能看到twofunction声明。 -
@Felix King 在您的回答中您正在使用 ES6 箭头功能对.. ?
标签: node.js express asynchronous