【发布时间】:2019-06-20 06:13:20
【问题描述】:
所以我得到 SyntaxError: Unexpected token { on line "Question.prototype.displayQuestion() { "。但是代码看起来不错。有谁知道怎么回事?
function Question(question, answers, correct){
this.question = question;
this.answers = answers;
this.correct = correct;
}
Question.prototype.displayQuestion(){
console.log(this.question);
for(var i=0; i<this.answers.length; i++){
console.log(i + " : " + this.answers[i]);
}
}
【问题讨论】:
-
不,代码看起来不太好。原型属性必须通过赋值创建,没有“方法”语法。