2017-08-16 32 views
0

我得到一些非常奇怪的语法错误[未捕获的SyntaxError:意外的标识符]看似普通的代码。只是注释行奇怪的语法错误

得到一个错误,如果我写的其他块1号线后什么..

if (classlist.length == 0) {  
     lastClickCatID = -1; 
} 
else { 
    lastClickCatID = +classlist.value.split('-')[1]; 
    // **Getting error if I write anything here, even for comments like this** 
} 

获取错误,如果我只用两个词语的注释(与它们之间的空间)。当然,任何JS语句都会出错,甚至是基本的控制台日志。

另外,得到一个错误为在下面的代码的console.log线已注释(第4行:console.log-“UNDO”):

// Push this data into the undo array 
undo.push([lastClickDivID, lastClickCol, lastClickRow, lastClickCatID, nextClickCatID]); 

//console.log("UNDO", undo[0][0], undo[0][1], undo[0][2], undo[0][3], undo[0][4]); // *Getting error if I include this line* 
console.log(undo.pop()); 

获得一个误差或没有评论标签。但是,如果我删除整条线,它工作正常。

我有另一行:

nextClickCatID = +id2; 

做变量的的console.log再次收到错误信息。但它工作正常,如果我删除'+',只使用下一个'nextClickCatID = id2; ”。

在这个函数中也会出现许多其他奇怪的错误(如果包含它们,它会变得太长)。任何想法为什么我得到像这些看似正常的代码错误?

+0

您能告诉我们一个更完整的代码示例吗?或者最好是您的问题代码片段中的错误的实际示例 –

+0

为什么您的变量有+号? –

+1

@N。伊凡诺夫 - +符号将它们解析为int。即使我完全删除它,或者使用parseInt,我也会收到一些错误。 – user3001859

回答

0

我已经解决了。当我在jquery文档就绪函数中删除()和大括号之间的空格时奇怪地工作。从改变...

$(function() { 

到:

$(function(){ // with no space between the parentheses and the curly brackets 

我想补充一点 - 它是具有相同结构的工作之前罚款(与空间括号),而所有这一切。但突然决定今天在一个特定的功能发生错误。如果有人能够澄清为什么发生这种情况,它仍然是非常相关的。