Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
374 views
in Technique[技术] by (71.8m points)

javascript - JSLint突然报告:使用“使用严格”功能形式(JSLint is suddenly reporting: Use the function form of “use strict”)

I include the statement:

(我包括以下声明:)

"use strict";

at the beginning of most of my Javascript files.

(在我大多数Javascript文件的开头。)

JSLint has never before warned about this.

(JSLint从未对此发出警告。)

But now it is, saying:

(但现在是这样说:)

Use the function form of "use strict".

(使用“使用严格”的功能形式。)

Does anyone know what the "function form" would be?

(有谁知道“函数形式”是什么?)

  ask by Zhami translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 */

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...