pixelmike
pixelmike

Reputation: 1983

How to prevent "missing use strict" at end of IIFE assigned to variable?

Using jshint, if you have something like:

var Thing = (function(){
    "use strict";
    // code and stuff...
}());

I get a "missing use strict" error on the last line. I suppose this is because the var Thing = falls outside of the strict scope. Is there a way to prevent this warning without turning off the use strict warnings entirely?

Upvotes: 0

Views: 90

Answers (2)

Pierre Inglebert
Pierre Inglebert

Reputation: 3930

In your .jshintrc, remove globalstrict: true and use strict: true http://jshint.com/docs/options/#strict

globalstrict is for file scope 'use strict' and strict is for fonction scope (the one you want).

Upvotes: 1

Artyom Neustroev
Artyom Neustroev

Reputation: 8715

You can use one more wrapper:

(function(namespace) {
   'use strict';

   namespace.Thing = (function() {
     // code here
   })();

})(window);

Upvotes: 1

Related Questions