[英]Using “use strict” but still get the warning
HI guys Im trying to get use to using JSLint and I am getting the 'use strict' warning and after adding it to the function I still get the missing 'use strict' statement 嗨,大家好,我试图习惯于使用JSLint,并且收到“使用严格”警告,将其添加到函数中后,我仍然收到缺少的“使用严格”语句
fs.readFile('file', 'utf8', function (err, data) {
if (err) { "use strict"; throw err; }
var obj = JSON.parse(data);
});
i was curious to what i am doing wrong? 我很好奇我做错了什么?
I'm not 100% positive on this, but I've only ever used 'use strict';
我对此不是100%正面的,但是我只使用过'use strict';
at the top of a given .js file, not embedded in the code. 在给定.js文件的顶部,而不是嵌入在代码中。 And I've not gotten the warning after doing so. 而且这样做之后我还没有得到警告。 Perhaps that's where jslint looks for it. 也许这就是jslint寻找它的地方。
Further, looking at the documentation for it, use strict
should be scoped either to the whole script, (top of the file) or to a given function (top of the function, right after the opening brace). 此外,在查看相关文档的过程中, use strict
应该限制在整个脚本(文件顶部)或给定函数(函数顶部,右括号后)的范围内。 So regardless of jslint's capabilities, that should be fixed. 因此,不管jslint的功能如何,都应该将其修复。
The location of the "use strict"
directive is the issue. 问题是"use strict"
指令的位置。
Usages: 用途:
// Top of script file
"use strict";
/* ... code ... */
Or: 要么:
function b() {
"use strict";
/* ... code ... */
}
You're using it inside the block of an if
branch. 您正在if
分支的块内使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.