jshint: 'use the function form of "use strict"' and 'document is not defined'

I have bundled these together because I think they are related.The most simplest of simple bits of cod

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:

  1. are these warnings, or errors, and how can I tell this for myself?

  2. how do I and indeed do I need to, circumvent the use strict thing?

  3. 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:

  1. are these warnings, or errors, and how can I tell this for myself?

  2. how do I and indeed do I need to, circumvent the use strict thing?

  3. how do I and indeed do I need to, circumvent the document is not defined thing?

Share edited Jan 1, 2019 at 17:15 Cœur 38.8k25 gold badges206 silver badges278 bronze badges asked Oct 14, 2018 at 21:38 JL_SOJL_SO 1,9412 gold badges28 silver badges46 bronze badges 4
  • 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
Add a ment  | 

1 Answer 1

Reset to default 8

You’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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信