我正在使用lazy
模块来解析带有用户标识的文件,并检查特定用户是否在其中。 modCheck应该返回true/false,但是它会返回undefined。函数返回undefined而不是true/false
var fs = require("fs");
var lazy = require("lazy");
function parseLineToString(line) {
//checks to see if line is empty
if (line == undefined) {
return "";
} else {
return line.toString();
}
}
function modCheck(channel, message) {
var readStreamMC = fs.createReadStream("channel_mods/"+getChannelID(channel));
//opens a read stream to a file depending on the string "channel"
readStreamMC.on("end", function() {
//after parsing all the lines, if it hasn't returned true, return false
return false;
});
//using lazy to parse all the lines in a file
new lazy(readStreamMC)
.lines
.forEach(function(line){
//message.user is a 21 character user id
if (parseLineToString(line).slice(0, 21) == message.user) {
return true;
}
});
}
那些返回值只从匿名函数范围返回,而不是modCheck范围。 – 2015-02-06 22:12:51
*“isMod应返回true/false,而是返回undefined”*好的。向我们展示'isMod'的代码,也许我们可以提供帮助。 – 2015-02-06 22:12:54
***叹息***另一个问题和运行 – 2015-02-06 22:21:10