2016-05-14 168 views
0

在我的Web應用程序中使用以下代碼時,我從ESLint獲得以下返回值。我寧願使用這種循環方法而不是增量I方法。這個錯誤是什麼意思?這是否意味着循環的使用有問題?eslint:「解析錯誤:意外的令牌」

錯誤消息:

Parsing error: Unexpected token of 

實際影響的代碼:

renderCanvas: function() { 
    console.log("Rendering Model"); 
    var canvases = document.getElementsByClassName("DesignerCanvas"); 
    for (var canvas of canvases) { 
    var ctx = canvas.getContext('2d'); 

    ctx.beginPath(); 
    // String for Hanging 
    ctx.closePath(); 

    ctx.beginPath(); 
    // Top Trimming 
    ctx.closePath(); 

    ctx.beginPath(); 
    // Outter Shade Body 
    ctx.closePath(); 

    ctx.beginPath(); 
    // Bottom Trimming 
    ctx.closePath(); 

    ctx.beginPath(); 
    // Inner Shade Body 
    ctx.closePath(); 
    } 
} 
+0

它看起來像ESLint不理解'for..of',因爲它抱怨''的' – slebetman

回答

3

for-of環是一個6的EcmaScript特徵,並且這些默認不ESLint啓用。

按照documentation

What about ECMAScript 6 support?
ESLint has full support for ECMAScript 6. By default, this support is off. You can enable ECMAScript 6 support through configuration .

如果然後按照配置鏈接,它會告訴你,你可以使es6環境

/*eslint-env es6 */ 
JavaScript文件中

,或者

{ 
    "env": { 
     "es6": true 
    } 
} 

在配置文件中。