asynchronous瀑布传递参数

我有一个关于在async.waterfall()中传递参数到第三个函数而不是第一个函数的问题。 例如,如下所示

async.waterfall([ first, second, async.apply(third, obj) ], function(err, result){}); 

现在可以在名为third的函数中使用“obj”作为参数,也可以使用从名为second的函数的callback函数传递的参数

是。 你可以做到这一点。 见下文。 看最后一个function。

  var async = require('async'); async.waterfall([ myFirstFunction, mySecondFunction, async.apply(myLastFunction, 'deen'), ], function (err, result) { console.log(result); }); function myFirstFunction(callback) { callback(null, 'one', 'two'); } function mySecondFunction(arg1, arg2, callback) { // arg1 now equals 'one' and arg2 now equals 'two' callback(null, 'three'); } function myLastFunction(arg1, arg2, callback) { // arg1 is what you have passed in the apply function // arg2 is from second function callback(null, 'done'); }