Jshint.com 要求“严格使用”。这意味着什么?
Jshint.com 给出错误:
第 36 行:varsignin_found;缺少“use strict”声明。
Jshint.com is giving the error:
Line 36: var signin_found; Missing "use strict" statement.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 js 文件顶部添加“use strict”(在 .js 文件的第 1 行):
有关 stackoverflow 上另一个问题的更多有关“use strict”的信息:
“use strict”在 JavaScript 中做什么,背后的推理是什么是吗?
更新。
jshint.com 有问题,它要求您在每个函数中放置“use strict”,但应该允许为每个文件全局设置它。
jshint.com 认为这是错误的。
但它没有任何问题......
它希望你对每个函数添加“use strict”:
然后它说:
Add "use strict" at the top of your js file (at line 1 of your .js file):
More about "use strict" in another question here on stackoverflow:
What does "use strict" do in JavaScript, and what is the reasoning behind it?
UPDATE.
There is something wrong with jshint.com, it requires you to put "use strict" inside each function, but it should be allowed to set it globally for each file.
jshint.com thinks this is wrong.
But there is nothing wrong with it...
It wants you to put "use strict" to each function:
Then it says:
这里是 JSHint 维护者。
JSHint(网站上使用的版本)要求您在代码中使用函数级严格模式。关闭它非常容易,您只需取消选中“代码不处于严格模式时发出警告”复选框:
为什么我们不允许@Czarek 建议的全局严格模式?因为页面上使用的某些 JavaScript 文件可能与严格模式不兼容,而全局严格模式会破坏该代码。要使用全局严格模式,有一个名为
globalstrict
的选项。希望有帮助!
JSHint maintainer here.
JSHint—the version used on the website—requires you to use function-level strict mode in your code. It is very easy to turn that off, you just need to uncheck "Warn when code is not in strict mode" checkbox:
Why don't we allow global strict mode as suggested by @Czarek? Because some of the JavaScript files used on your page might not me strict mode compatible and global strict mode will break that code. To use global strict mode, there is an option called
globalstrict
.Hope that helps!
我认为这是因为 jshint 试图“保护”我们免受意外分配严格模式到整个文件的影响。
用匿名函数包装代码或使用某种命名空间也很好。
例如,两者都在严格模式下运行:
I think its because jshint is trying to "protect" us against accidental assignment strict mode to entire file.
And also it is good to wrap code with anonymous function, or use somekind of namespace.
e.g. both function in strict mode:
JSlint 要求您的代码处于“严格模式”。
为此,只需将
"use strict";
添加到代码顶部即可。JSlint requires your code to be in 'strict mode'
To do this simply add
"use strict";
to the top of your code.