失踪 ; 声明之前,JavaScript

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19040984/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 14:09:37  来源:igfitidea点击:

Missing ; before statement, JavaScript

javascript

提问by CodeNewbie

I'm trying something with JavaScript. I keep getting this error for the following code block -

我正在尝试使用 JavaScript 进行一些操作。对于以下代码块,我不断收到此错误 -

"There is a missing ; before statement." 

And the statement referred to is the for loop after the function TeamConst. Any idea why?!

而所指的语句就是函数后面的for循环TeamConst。知道为什么吗?!

function Semis1TieBreakCheck(){

      function TeamConst(TeamName, rd1, rd2, semiscomb){
        this.TeamName = TeamName;
        this.rd1 = rd1;
        this.rd2 = rd2;
        this.semiscomb = semiscomb;
      };

      for(var i = 0; i <= numofTeams-0; i++){
        var team[i] = new TeamConst(values[i+2][5],values[i+2][6],values[i+2][7],values[i+2][6] + values[i+2][7]);
      };

    };

回答by Paul

You can't declare a property of an object/array using the varkeyword.

您不能使用var关键字声明对象/数组的属性。

Change var team[i] = ...to just team[i] = ....

更改var team[i] = ...team[i] = ....

Also make sure that team is declared somewhere. If it is not already declared in an outer scope then add this before your loop:

还要确保该团队在某处声明。如果它尚未在外部作用域中声明,则在循环之前添加它:

var team = [];

回答by Christian Fritz

I don't get that error, but there is a different one. You need to define teamfirst.

我没有得到那个错误,但有一个不同的错误。你需要先定义team

var team = [];                                                                                            
for (var i = 0; i <= numofTeams-0; i++) {
   team.push(new TeamConst(values[i+2][5],
                           values[i+2][6],
                           values[i+2][7],
                           values[i+2][6] + values[i+2][7])
            );                                                                                                            
};