我的问题如下:我想返回回调返回的结果。
exports.process_logs = function(file, process_func, process_parsedLog) {
var logs = [];
var log = null;
var counter = 0;
fs.readFile(file, 'utf8', function(read_error, content) {
if (read_error) return sys.error(read_error);
// TODO:: Remove these hardcode rails filters
// switch filters and split functions to a nested helper in process func
content.split(/Processing /).forEach(function(msg, index) {
if ((tmp = process_func(msg, index)))
logs.push(tmp);
});
log = process_parsedLog(logs);
});
console.log(log);
return log;
};
但是变量“log”仍然为空,尽管当我在“log = process_parsedLog(logs);”之后使用 console.log(log) 检查它时 给出正确的结果。