【发布时间】:2017-06-19 03:23:51
【问题描述】:
function Course(title,instructor,level,published,views){
this.title = title;
this.instructor = instructor;
this.level = level;
this.published = published;
this.updateViews = function() {
return ++this.views;
}
}
var courses = [
new Course("A title", "A instructor", 1, true, 0)
new Course("B title", "B instructor", 1, true, 123456)
];
console.log(courses);
我得到的错误是
Untaught Syntaxerror: Unexpected Token New
当我在同一个对象数组中第二次使用“新”这个词时。
(例如,如果我删除了new Course("B title", "B instructor", 1, true, 123456) 行,代码可以正常工作
我在这里做错了什么?
【问题讨论】:
-
我认为你在数组中漏掉了一个逗号
-
投票结束,这只是一个简单的错字。
标签: javascript arrays object error-handling syntax-error