简体   繁体   English

为什么 jslint 在模板字符串上抱怨 Unexpected '`'

[英]Why does jslint complain Unexpected '`' on template strings

I am using JSLint with syntastic in Vim and when I have a simple .js file like so我在 Vim 中使用 JSLint 和 syntastic,当我有一个像这样的简单.js文件时

var a = 99;
var b = `I am ${a} years old`;

Why does Syntastic (and thus jslint) give me this error为什么 Syntastic(以及因此 jslint)给我这个错误

Unexpected '`'

Okay, I think you're asking a trick question.好吧,我想你在问一个技巧问题。 With the most recent version of JSLint, your code lints fine.使用最新版本的 JSLint,您的代码 lints 很好。

Try it out on jslint.com .jslint.com上尝试一下。

It used to be that JSLint didn't support es6 (ES2015) features out of the box , and you had to explicitly tell it you were using es6.过去JSLint 不支持开箱即用的 es6 (ES2015) 功能,您必须明确告诉它您使用的是 es6。

Template literals (`) weren't a thing until ES2015 (again, aka es6), which leaves out many browsers .模板文字 (`) 直到 ES2015(又名 es6)才出现,它遗漏了许多浏览器 And older copies of JSLint assumed you were serving up your JavaScript as written to browsers that might only be es5 compliant unless you told it you're in ES2015 (es6) mode.并且 JSLint 的旧副本假定您将 JavaScript 写入可能仅符合 es5 的浏览器,除非您告诉它您处于 ES2015 (es6) 模式。

So try putting /*jslint es6 */ at the top of your file and see if it lints.因此,尝试将/*jslint es6 */放在文件顶部,看看它是否 lints。

But more importantly: Update your version of JSLint.但更重要的是:更新您的 JSLint 版本。

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

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