eslint: "Parsing error: Unexpected token of"
eslint: "Parsing error: Unexpected token of"
在我的网络应用程序中使用以下代码时,我从 ESLint 获得以下 return。我更喜欢使用这种循环方法而不是增量 I 方法。这个错误是什么意思?这是否意味着循环的使用有问题?
错误信息:
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();
}
}
for-of
循环是 EcmaScript 6 的一个特性,这些在 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.
如果您随后按照配置 link,它会告诉您可以使用
启用 es6
环境
/*eslint-env es6 */
在 JavaScript 文件中,或
{
"env": {
"es6": true
}
}
在配置文件中。
在我的网络应用程序中使用以下代码时,我从 ESLint 获得以下 return。我更喜欢使用这种循环方法而不是增量 I 方法。这个错误是什么意思?这是否意味着循环的使用有问题?
错误信息:
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();
}
}
for-of
循环是 EcmaScript 6 的一个特性,这些在 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.
如果您随后按照配置 link,它会告诉您可以使用
启用es6
环境
/*eslint-env es6 */
在 JavaScript 文件中,或
{
"env": {
"es6": true
}
}
在配置文件中。