RRP*_*RRP 9 node.js node-async
我有一个问题,关于将async.waterfall()中的参数传递给第三个函数而不是第一个函数.例如,如下
async.waterfall([
first,
second,
async.apply(third, obj)
], function(err, result){});
Run Code Online (Sandbox Code Playgroud)
现在可以在名为third的函数中使用"obj"作为参数,并且还可以使用从名为second的函数的回调传递下来的参数
Dee*_*arg 24
是.你可以做到这一点.见下文.看到最后一个功能.
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');
}
Run Code Online (Sandbox Code Playgroud)