Coder Perfect

Use the function form of “use strict” according to JSLint.


I also include the following statement:

"use strict";

at the start of the majority of my Javascript files

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

Is there anyone who knows what the “function form” is?

Asked by Zhami

Solution #1

Use strict as the first line in a wrapped function to ensure that it only impacts that function. When concatenating scripts that aren’t strict, this prevents difficulties.

Strict Mode Is Coming To Town, by Douglas Crockford, is a recent blog entry.

This is an 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 (e.g. it is a node module), then you can disable the warning.

According to Zhami, for JSLint:

/*jslint node: true */

For JSHint:

/*jshint strict:false */

alternatively (per Laith Shadeed)

/* jshint -W097 */

Check the map in the JSHint source code to disable any random warning from JSHint (details in docs).

JSHint now supports the node:boolean option. On github, look for.jshintrc.

/* jshint node: true */

Answered by bdukes

Solution #2

If you’re building NodeJS modules, you’ll find that they’ve already been encapsulated. Include the following at the top of your file to inform JSLint that you have node:

/*jslint node: true */

Answered by Zhami

Solution #3

Instead, I recommend using jshint.

It is possible to disable this warning by using /*jshint globalstrict: true*/.

If you’re developing a library, I’d only recommend using global strict if your code is divided into modules, as nodejs does.

Otherwise, everyone who uses your library will be forced to use it in strict mode.

Answered by Thorsten Lorenz

Solution #4

Following the Cross Platform JavaScript blog post, I began developing a Node.js/browserify application. And I had this problem because my fresh new Gruntfile failed the jshint test.

Fortunately, I found an answer in the Leanpub Grunt book:

Adding node: true to the jshint options, to put jshint into “Node mode”, removed both errors for me.

Answered by qris

Solution #5

Add the following content to a.jslintrc (or.jshintrc in the case of jshint) file at the root of your project:

    "node": true

Answered by Sahil Ahuja

Post is based on