Include 'use strict';
(包括'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.(这样可以防止在连接不严格的脚本时出现问题。)
See Douglas Crockford's latest blog post Strict Mode Is Coming To Town .(请参阅道格拉斯·克罗克福德(Douglas Crockford)最新的博客文章“ 严格模式即将来临” 。)
Example from that post:(该帖子中的示例:)
(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 (eg it is a node module), then you can disable the warning.(更新:如果您不想包装立即函数(例如,它是一个节点模块),则可以禁用警告。)
For JSLint (per Zhami ):(对于JSLint (每个Zhami ):)
/*jslint node: true */
For JSHint :(对于JSHint :)
/*jshint strict:false */
or (per Laith Shadeed )(或(根据Laith Shadeed的说法 ))
/* jshint -W097 */
To disable any arbitrary warning from JSHint, check the map in JSHint source code (details in docs ).(要禁用来自JSHint的任何警告,请检查JSHint源代码中的映射(在docs中有详细信息)。)
Update 2: JSHint supports node:boolean
option.(更新2: JSHint支持node:boolean
选项。)
See .jshintrc
at github .(参见github上的.jshintrc
。)
/* jshint node: true */
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…