![](/img/trans.png)
[英]Why am I getting the “Cannot set property 'border' of undefined” error?
[英]Why am i getting error of “cannot set property of undefined”?
const quiz = new quiz(questions); populate(); function Question(text, choices, answer){ this.text = text; this.choices = choices; this.answer = answer; } Question.prototype.correctAnswer = function(choices){ return choice === this.answer; } function Quiz(questions){ this.score = 0; this.questions = questions; this.questionIndex = 0; } quiz.prototype.getQuestionIndex = function(){ return this.questions[this.questionIndex]; } quiz.prototype.isEnded = function(){ return this.questions.length === this.questionIndex; } quiz.protype.guess = function(answer){ this.questionIndex++; if(this.getQuestionIndex().correctAnswer(answer)){ this.score++; } }
当我运行此代码时,它说它无法将“getQuestionIndex”设置为未定义。 但是Ique不是将它设置为0吗? 我在 Quiz 构造函数中将 this.questionIndex 设置为 0。 我在这里想念什么?
const quiz = 新测验(问题); 应该是 const quiz = new Quiz (questions);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.