问题
I get this error: "expected an identifier and instead saw 'const'", I'm using brackets text editor. I found this answer: "You need to specify the es6 directive. See JSLint Help". But I can't figure it out how to specity the es6 directive in brackets. Here's my code:
const singleQuotes = '<p>Single quotes</p>';
const doubleQuotes = "<p>Double quotes</p>";
const stringLiterals = `<p>String literlas</p>`;
const result = singleQuotes + doubleQuotes + stringLiterals;
document.querySelector('.basic').innerHTML = result;
I appreciate any help. It works fine if I use var.
回答1:
One File
If I remember right, you put the following at the very top of your file:
/*jslint es6:true*/
Project Wide
If you want all files in your project to abide ES6, you can add a .brackets.json
file to the root of your project.
Brackets Wide
If you want all files to abide ES6, you can modify your User-global preferences by clicking the following menu items: Debug -> Open Preferences
and then adding the jslint.options
property to your preferences.
See How-to-Use-Brackets: Preferences for more information.
However, I just tried to do this with my Brackets installation with all extensions disabled and Brackets doesn't understand the directive. I think Brackets has a very old version of jslint installed by default. You may want to use some extensions to try to supplement the old version.
What I ended up doing was installing the brackets-jshint and changing my brackets preferences file to use jshint by default with the following option:
{
"language": {
"javascript": {
"linting.prefer": [
"JSHint"
],
"linting.usePreferredOnly": true
}
}
}
回答2:
Try putting a comment at the top of the file like this, as documented in JSLint Help...
/*jslint
es6
*/
const singleQuotes = '<p>Single quotes</p>';
const doubleQuotes = "<p>Double quotes</p>";
const stringLiterals = `<p>String literlas</p>`;
const result = singleQuotes + doubleQuotes + stringLiterals;
document.querySelector('.basic').innerHTML = result;
来源:https://stackoverflow.com/questions/44686144/how-to-set-the-jslint-es6-directive-in-brackets