Why does JSHint throw a warning if I am using const?(如果我使用 const,为什么 JSHint 会发出警告?)
问题描述
这是我在使用 const 时遇到的错误:
This is the error I get when using const:
<error line="2" column="1" severity="warning" message="'const' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz)." source="jshint.W104" />
我的代码如下所示:
const Suites = {
Spade: 1,
Heart: 2,
Diamond: 3,
Club: 4
};
代码运行良好,只有 JSHint 每次都警告我.
The code works fine only JSHint is warning me every time.
推荐答案
当依赖 ECMAScript 6 功能(例如 const
)时,您应该设置此选项,以便 JSHint 不会引发不必要的警告.
When relying upon ECMAScript 6 features such as const
, you should set this option so JSHint doesn't raise unnecessary warnings.
/*jshint esnext: true */(编辑 2015.12.29:更新语法以反映 @Olga 的评论)
/*jshint esnext: true */ (Edit 2015.12.29: updated syntax to reflect @Olga's comments)
/*jshint esversion: 6 */
const Suites = {
Spade: 1,
Heart: 2,
Diamond: 3,
Club: 4
};
顾名思义,此选项告诉 JSHint 您的代码使用 ECMAScript 6 特定的语法.http://jshint.com/docs/options/#esversion
This option, as the name suggests, tells JSHint that your code uses ECMAScript 6 specific syntax. http://jshint.com/docs/options/#esversion
Edit 2017.06.11:基于this answer添加了另一个选项.
Edit 2017.06.11: added another option based on this answer.
虽然内联配置适用于单个文件,但您也可以通过在项目的根目录中创建 .jshintrc
文件并将其添加到其中,为整个项目启用此设置.
While inline configuration works well for an individual file, you can also enable this setting for the entire project by creating a .jshintrc
file in your project's root and adding it there.
{
"esversion": 6
}
这篇关于如果我使用 const,为什么 JSHint 会发出警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如果我使用 const,为什么 JSHint 会发出警告?


- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01