简体   繁体   English

eslint:“解析错误:的意外令牌”

[英]eslint: “Parsing error: Unexpected token of”

When using the following code in my web app I get the following return from ESLint. 在我的Web应用程序中使用以下代码时,我从ESLint获得以下返回。 I would prefer using this loop method as opposed to the increment I method. 与使用增量I方法相比,我更喜欢使用这种循环方法。 What does this error mean? 这个错误是什么意思? And does it mean there is something wrong with the use of the loop? 这是否意味着使用循环有问题?

Error Message: 错误信息:

Parsing error: Unexpected token of

Actual effected code: 实际生效的代码:

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();
  }
}

for-of loops are an EcmaScript 6 feature, and these are not enabled by default in ESLint. for-of循环是EcmaScript 6的一项功能,默认情况下,ESLint中未启用这些功能。

According to the documentation : 根据文档

What about ECMAScript 6 support? ECMAScript 6支持如何?
ESLint has full support for ECMAScript 6. By default, this support is off. ESLint完全支持ECMAScript6。默认情况下,此支持为关闭状态。 You can enable ECMAScript 6 support through configuration . 您可以通过配置启用ECMAScript 6支持。

If you then follow the configuration link, it tells you that you can enable the es6 environment with 如果您随后es6配置链接,它将告诉您可以使用以下命令启用es6环境:

/*eslint-env es6 */

in the JavaScript file, or 在JavaScript文件中,或

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

in the configuration file. 在配置文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM