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.

JSLint has never before warned about this. But now it is, saying:

Use the function form of "use strict".

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


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.

See Douglas Crockford's latest blog post Strict Mode Is Coming To Town.

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 node: true */

For JSHint :

/*jshint strict:false */

or (per Laith Shadeed)

/* jshint -W097 */

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

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

/* jshint node: true */

If you're writing modules for NodeJS, they are already encapsulated. Tell JSLint that you've got node by including at the top of your file:

/*jslint node: true */

I'd suggest to use jshint instead.

It allows to suppress this warning via /*jshint globalstrict: true*/ .

If you are writing a library, I would only suggest using global strict if your code is encapsulated into modules as is the case with nodejs.

Otherwise you'd force everyone who is using your library into strict mode.

链接地址: http://www.djcxy.com/p/3174.html

上一篇: Visual Studio / ReSharper的主要启动器插件

下一篇: JSLint突然报道:使用“使用严格”的函数格式