I have bundled these together because I think they are related. The most simplest of simple bits of code:
'use strict';
const x = document.querySelector('#score strong');
is resulting in the following
"use the function form of use strict (W097)"
"document is not defined (W117)"
which may be errors or warnings; the W suggests a warning but I don't know how to determine this.
So, another question: are these warnings, or errors, and how can I tell this for myself? Where is this referenced?
I am using Atom 1.31, with I think JSHint (whatever that is - I am new to all this). I am using ES6 - .jshintrc:
{
"esversion": 6
}
How should I be specifying use strict globally? Putting it in a function so that it's used globally means, er, putting the whole contents of my script inside a function. No? Yes?
And how do I circumvent this document is not defined thing? I have tried
const document=this.document;
const document=global.document;
const document=window.document;
All result in warnings/errors (whatever).
So, to be clear, my questions are:
are these warnings, or errors, and how can I tell this for myself?
how do I and indeed do I need to, circumvent the use strict thing?
how do I and indeed do I need to, circumvent the document is not defined thing?
I have bundled these together because I think they are related. The most simplest of simple bits of code:
'use strict';
const x = document.querySelector('#score strong');
is resulting in the following
"use the function form of use strict (W097)"
"document is not defined (W117)"
which may be errors or warnings; the W suggests a warning but I don't know how to determine this.
So, another question: are these warnings, or errors, and how can I tell this for myself? Where is this referenced?
I am using Atom 1.31, with I think JSHint (whatever that is - I am new to all this). I am using ES6 - .jshintrc:
{
"esversion": 6
}
How should I be specifying use strict globally? Putting it in a function so that it's used globally means, er, putting the whole contents of my script inside a function. No? Yes?
And how do I circumvent this document is not defined thing? I have tried
const document=this.document;
const document=global.document;
const document=window.document;
All result in warnings/errors (whatever).
So, to be clear, my questions are:
are these warnings, or errors, and how can I tell this for myself?
how do I and indeed do I need to, circumvent the use strict thing?
how do I and indeed do I need to, circumvent the document is not defined thing?
- 3 1) These are warnings created from the static analysis of your code by the linting feature of Atom. They are warnings because JSHint (the linting ruleset) cannot read your mind about where you might use this code. So it does the best is can to say Hey! You might want to take an extra look at this!. Your code may or may not work regardless of these errors. Now that you know it is JSHint, read the docs: jshint./docs – Randy Casburn Commented Oct 14, 2018 at 21:44
- Many people just turn off many of these rules. That is not remended. Understanding the rules will make you a better JavaScript programmer! – Randy Casburn Commented Oct 14, 2018 at 21:46
- 1 Your question is a question and it should still be a question in the future. Don't edit in answers please. – Jonas Wilms Commented Jan 1, 2019 at 15:34
- 2 @RandyCasburn if you know a good answer, answer ... I edited your ment into the munity wiki, feel free to rollback :) – Jonas Wilms Commented Jan 1, 2019 at 15:41
1 Answer
Reset to default 8You’ll need to set the strict
option to prefer a global 'use strict'
, and the browser
option to tell JSHint that your script targets browsers.
.jshintrc
{
"esversion": 6,
"browser": true,
"strict": "global"
}
And yes, “W” at the beginning of a code means “warning”.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745097336a4611059.html
评论列表(0条)