JSLint突然报告:使用“use strict”的功能形式 [英] JSLint is suddenly reporting: Use the function form of "use strict"

查看:131
本文介绍了JSLint突然报告:使用“use strict”的功能形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我包括声明:

"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:


使用use strict的函数形式。

Use the function form of "use strict".

有谁知道功能形式是什么?

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 (每Zhami

/*jslint node: true */

对于 JSHint

/*jshint strict:false */

或(每 Laith Shadeed

/* jshint -W097 */

禁用任意警告来自JSHint,请查看 JSHint源代码中的地图(详情请参阅 docs )。

To disable any arbitrary warning from JSHint, check the map in JSHint source code (details in docs).

更新2: JSHint 支持否de:boolean 选项。请参见 .jshintrc 在github

Update 2: JSHint supports node:boolean option. See .jshintrc at github.

/* jshint node: true */

这篇关于JSLint突然报告:使用“use strict”的功能形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆