jslint --edition =最新意外的ES6功能。常量 [英] jslint --edition=latest Unexpected ES6 feature. const

查看:1321
本文介绍了jslint --edition =最新意外的ES6功能。常量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用node-jslint https://github.com/reid/node-jslint 为了保持我的代码清洁

I'm trying to use node-jslint https://github.com/reid/node-jslint in order to keep my code clean

我的nodejs脚本中有一个const,但是jslint表示这是无效的ES6代码

I've got a const in my nodejs script, but jslint says it isn't valid ES6 code

 Unexpected ES6 feature.
const pdPersonsFilterId = process.argv[2]; // Line 10, Pos 0

这是我在控制台中使用的命令

Here is the command I use in the console

jslint --edition=latest index.js

根据 https:/ /developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const 可以使用全局常量。

According to the https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const it possible to use global constants.

为什么jslint不认为这个代码是有效的?

Why does jslint does not consider this code to be valid?

推荐答案

JSLint对ES6很满足;你只需要知道你在使用ES6。将 es6 指令添加到您的JSLint配置或文件顶部,并获利。

JSLint is happy enough with ES6; you just have to let it know you're using ES6. Add the es6 directive to your JSLint config or atop your file, and profit.

/*jslint es6 */
const pdPersonsFilterId = process.argv[2];

现在您看到的警告消失了。

Now the warning you saw goes away.

JSLint的帮助


第六版ECMAScript [ES6]可能需要时间达到
无所不在。使用不完全
的环境中的新功能实施新标准将导致失败。这就是为什么JSLint在使用ES6功能时给出
警告。 ES6的一些功能很好,
,所以JSLint将会使用es6选项来识别ES6的很好的部分。
由于
新标准的实现变得更加稳定,更好的
了解,JSLint认可的一组功能可能会增加。
过渡到ES6后,es6选项将被
删除。
[emph我的]

It may take time for the sixth edition of ECMAScript [ES6] to reach ubiquity. Using the new features in enviroments that do not fully implement the new standard will result in failure. This is why JSLint gives warnings when ES6 features are used. Some of ES6's features are good, so JSLint will recognize the good parts of ES6 with the es6 option. As implementations of the new standard become more stable and better understood, the set of features recognized by JSLint may increase. After the transition to ES6 is complete, the es6 option will be dropped. [emph mine]

看起来很公平所以你看到的只是警告你,你所得到的可能不会在ES6不受支持的地方,因为现在很多地方。一旦ES6越来越普遍,或者如果您明确地让Crockford知道您打算使用ES6 ,那么警告将会消失。 (TJ的观点可能就是,至少在Node上,现在删除警告的时候了; ^ D)

Seems fair enough. So what you saw was just warning you that what you've got might not work where ES6 isn't supported, since that's a lot of places right now. Once ES6 is more widespread -- or if you explicitly let Crockford know you intend to use ES6 -- the warning will go/goes away. (TJ's point might be that, at least with Node, the time to remove the warning is now. ;^D)

这篇关于jslint --edition =最新意外的ES6功能。常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆