标签云

微信群

扫码加入我们

WeChat QR Code

jshint.com要求

This question already has an answer here:

Jshint.com is giving the error:

Line 36: var signin_found; Missing "use strict" statement.


ES5; yuiblog.com/blog/2010/12/14/strict-mode-is-coming-to-town

2018年06月18日00分50秒

You can ignore this warning by checking the option Tolerate missing 'use strict' pragma (right column).

2018年06月18日00分50秒

I've corrected my answer.

1970年01月01日00分03秒

Updated my answer again, hope this time it helps.

2018年06月19日00分50秒

Actually, some (incorrect) scripts could try to simply concatenate multiple scripts, resulting in incorrect code(non-strict code being executed as strict). Making code strict per-function solves this problem.

2018年06月19日00分50秒

It is not that uncommon for bundling tools to concatenate JS files and cause this problem. Really, you should wrap your whole file in an IIFE to avoid this and accidentally putting variables in the global scope. See lenrok7 answer for how to do this.

2018年06月18日00分50秒

I don't see that "globalstrict" option on the screenshot, is it hidden somewhere? Why not add another checkbox called "Allow global strict", just below "When code is not in strict mode", and make it default. I think that most people who use strict mode, do it for whole files, it is a little overkill to add such line to every function.

2018年06月19日00分50秒

For the sake of website's simplicity. You can read about all options in the docs and set them using /*jshint */ constructions. Basically, I don't want jshint.com front page to be intimidating with myriads of options.

2018年06月18日00分50秒

Can you help me set this option globally?stackoverflow.com/questions/9770968/passing-options-to-jshint

2018年06月18日00分50秒

Yes, you'll put it in just as "use strict"; The way ECMAScript 5 interprets this is as a function. ECMAScript 3 simply ignores it.

2018年06月18日00分50秒

What is the new code that you are passing through JSlint?

2018年06月19日00分50秒

Wrap your code in: (function(){ "use strict"; //rest of your code }());

2018年06月19日00分50秒

I also highly suggest giving this a read: ejohn.org/blog/ecmascript-5-strict-mode-json-and-more

2018年06月18日00分50秒

I'm not 100% if it's an issue with JSHint, but right now that's the only way to get around the error issue.

1970年01月01日00分03秒