问题描述
我包括声明:
"use strict";
在我的大多数Javascript文件的开头。
at the beginning of most of my Javascript files.
JSLint之前从未对此提出过警告。但现在是这样,说:
JSLint has never before warned about this. But now it is, saying:
有谁知道功能形式是什么?
Does anyone know what the "function form" would be?
推荐答案
包括'use strict';
作为包装函数中的第一个语句,因此它只影响该函数。这可以防止在连接不严格的脚本时出现问题。
Include 'use strict';
as the first statement in a wrapping function, so it only affects that function. This prevents problems when concatenating scripts that aren't strict.
请参阅Douglas Crockford的最新博文。
See Douglas Crockford's latest blog post Strict Mode Is Coming To Town.
该帖子的示例:
(function () {
'use strict';
// this function is strict...
}());
(function () {
// but this function is sloppy...
}());
更新:
如果您不想包装在立即函数中(例如它是一个节点模块),然后你可以禁用警告。
Update:In case you don't want to wrap in immediate function (e.g. it is a node module), then you can disable the warning.
对于 JSLint (每:
/*jslint node: true */
对于 JSHint :
/*jshint strict:false */
或(每)
/* jshint -W097 */
禁用任意警告来自JSHint,请查看中的地图(详情请参阅)。
To disable any arbitrary warning from JSHint, check the map in JSHint source code (details in docs).
更新2: JSHint 支持否de:boolean
选项。请参见。
Update 2: JSHint supports node:boolean
option. See .jshintrc
at github.
/* jshint node: true */
这篇关于JSLint突然报告:使用“use strict”的功能形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!