我在server.js中编写了以下函数,我一直得到error: uncaughtException: Cannot call method 'redirect' of undefined
function(req, res) {
async.waterfall([
function(next){
next(null, res);
},
function(next){
next(null, res);
},
function(next, res){
res.redirect('www.google.com')
}
]);
}
从下面的答案做出以上更改后,我得到了错误,如下所示:
2014-09-04T13:56:08.678Z - error: uncaughtException: Object function (err) {
if (err) {
callback.apply(null, arguments);
callback = function () {};
}
else {
var args = Array.prototype.slice.call(arguments, 1);
var next = iterator.next();
if (next) {
args.push(wrapIterator(next));
}
else {
args.push(callback);
}
async.nextTick(function () {
iterator.apply(null, args);
});
}
} has no method 'send'
答案 0 :(得分:5)
为什么需要将res作为瀑布参数传递?您可以在全局功能范围内使用它,就像这样
function(req, res) {
async.waterfall([
function(next){
next();
},
function(next){
next();
},
function(){
res.redirect('www.google.com')
}
]);
}