Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/477.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript错误对象数组的意外新标记_Javascript_Arrays_Object_Error Handling_Syntax Error - Fatal编程技术网

Javascript错误对象数组的意外新标记

Javascript错误对象数组的意外新标记,javascript,arrays,object,error-handling,syntax-error,Javascript,Arrays,Object,Error Handling,Syntax Error,我得到的错误是 未受教育的语法错误:意外的新标记 当我在同一个对象数组中第二次使用单词new时 e、 g.如果我删除了新课程B标题,B讲师,1,true,123456行,代码运行良好 我做错了什么?数组中没有逗号。修好它。它应该如下所示 功能课程主题、讲师、级别、已发布、视图{ this.title=标题; this.讲师=讲师; 这个水平=水平; this.published=published; this.updateViews=函数{ 返回++this.views; } } var课程=

我得到的错误是

未受教育的语法错误:意外的新标记

当我在同一个对象数组中第二次使用单词new时

e、 g.如果我删除了新课程B标题,B讲师,1,true,123456行,代码运行良好

我做错了什么?

数组中没有逗号。修好它。它应该如下所示

功能课程主题、讲师、级别、已发布、视图{ this.title=标题; this.讲师=讲师; 这个水平=水平; this.published=published; this.updateViews=函数{ 返回++this.views; } } var课程=[ 新课程A头衔,讲师,1,正确,0, 新课程B标题,B讲师,1,真实,123456 ];
控制台。日志课程;我想你在你的数组中漏掉了一个逗号,这只是一个简单的打字错误。
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);