Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
491 views
in Technique[技术] by (71.8m points)

javascript - 如果我使用const,为什么JSHint会发出警告?(Why does JSHint throw a warning if I am using const?)

This is the error I get when using const:(这是我在使用const时遇到的错误:)

<error line="2" column="1" severity="warning" message="&apos;const&apos; is available in ES6 (use esnext option) or Mozilla JS extensions (use moz)." source="jshint.W104" /> My code looks like this:(我的代码如下所示:) const Suites = { Spade: 1, Heart: 2, Diamond: 3, Club: 4 }; The code works fine only JSHint is warning me every time.(只有JSHint每次都警告我,代码才能正常工作。)   ask by Andre Schlesinger translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

When relying upon ECMAScript 6 features such as const , you should set this option so JSHint doesn't raise unnecessary warnings.(当依赖const等ECMAScript 6功能时,应设置此选项,以使JSHint不会引发不必要的警告。)

/*jshint esnext: true */ ( Edit 2015.12.29 : updated syntax to reflect @Olga's comments )(/ * jshint esnext:true * /编辑2015.12.29 :更新了语法以反映@Olga 的评论 )) /*jshint esversion: 6 */ const Suites = { Spade: 1, Heart: 2, Diamond: 3, Club: 4 }; This option, as the name suggests, tells JSHint that your code uses ECMAScript 6 specific syntax.(顾名思义,此选项告诉JSHint您的代码使用ECMAScript 6特定语法。) http://jshint.com/docs/options/#esversion(http://jshint.com/docs/options/#esversion) Edit 2017.06.11 : added another option based on this answer .(编辑2017.06.11 :基于此答案添加了另一个选项。) 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.(内联配置对于单个文件效果很好时,您还可以通过在项目的根目录中创建.jshintrc文件并将其添加到整个项目中来为整个项目启用此设置。) { "esversion": 6 }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...