0
我试着从另一个方法调用的方法中不定,所以我得到的错误是这样的:说,一个函数对象
TypeError: this.displayCur is not a function
错误是方法this.start
我的代码里面:
function Game(room , author) {
this.room = room;
this.author = author;
this.wrongLetters = [];
this.rightLetters = [];
this.guessesLeft = 5;
this.correctGuesses = [];
this.wrongGuesses = [];
this.start = function() {
dClient.on("message" , function(message) {
//this.prototype.guess(message);
if (!message.author.bot && this.guessesLeft > 0) {
console.log("Guess made: " + message);
} else if (!message.author.bot && this.guessesLeft <= 0) {
this.end();
}
this.displayCur("hello"); < ------ the error occurs here
});
};
this.displayCur = function(state) {
this.finStr = "";
for (var l = 0; l < this.word.length;l++) {
if (this.correctGuesses.includes(this.word[l])) {
this.finStr += this.word[l] + "\ \\";
} else {
this.finStr += "_" + "\ \\";
}
}
if (state != "begin") {
this.room.send(this.finStr);
}
};
this.displayCur("begin");
}
注意
我删除了一些代码,所以没有填充无关的代码。 所以如果你看到一些没有上下文的东西,请忽略它们。
哦,谢谢! :D解决了它。 – greuzr