2017-08-16 53 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 

我想補充一點 - 它是具有相同結構的工作之前罰款(與空間括號),而所有這一切。但突然決定今天在一個特定的功能發生錯誤。如果有人能夠澄清爲什麼發生這種情況,它仍然是非常相關的。