3

I have the following object in file remover.js:

'use strict';

(function( remover, $, undefined ) {
  // ...
  // Object's definition
  // ...
}( window.remover = window.remover || {}, jQuery ));

This is used on the external file main.js:

'use strict';

remover.doSomething();

The code is working but JSHint throws the following problem:

Running "jshint:all" (jshint) task

app/scripts/stuff/main.js
  line 3  col 1  'remover' is not defined.

✖ 1 problem

How to remove this warning?

Lucio
  • 4,753
  • 3
  • 48
  • 77

1 Answers1

10

You have two options, one is getting ride of all the undefined warnings which is bad for your debugging and another one is solving specifically the problem with global entities.

  1. Disable var undefined warnings (bad!)

    Just disable the warning on the main.js file with the undef option

    'use strict';
    /*jshint undef:false */
    
  2. Tell JSHint which are the external libraries (good!)

    Mention every variable as global

    'use strict';
    /*global remover */
    

Now running grunt jshint should output:

Running "jshint:all" (jshint) task

✔ No problems

There is more information at the section Directives in the JSHint Documentation.

Lucio
  • 4,753
  • 3
  • 48
  • 77