Software Archive
Read-only legacy content
17061 Discussions

Error warning in JS Hint problems

Adolfo_C_1
Beginner
377 Views

I´m using several .js files in my app with many global variables and constants declared in my first .js file and all js files declared in my html file. All run perfectelly in browser, emulate and in app Preview in my mobiles but when de variable is not in the same file the JS Hint inform that is not defined, the same problem with functions used in diferent files that is not the same that is called. The list is so huge that I can´t locate real erros in my JS Hint. I did something wrong? I was a AS3 programmer and there we use import declaration at the beginning of file. I search for the same resource for JS but I can find. Please help.

P.S.: I´m using a 3088 version of intel XDK

0 Kudos
1 Solution
Dale_S_Intel
Employee
377 Views

JSHint can be pickier than the browser, which is by design.  Fortunately there are a number of options to control it's behavior and solve problems like yours.

One would be to declare your globals in a comment like this:

/*jshint undef: true, unused: true */
/*global MY_GLOBAL */

 

You could also turn it off with:

//jshint undef:true

At least that's the what this site tells me.

EDIT: it is very important that there be no space between the opening comment marker and the jshint directives. Your jshint directives will be ignored if you do not follow this policy. Also, to make the /*global ... */ option easier to manage, put your globals inside a few objects, for example, rather than defining globals as:

var global1 = 0 ;
var global2 = 0 ;
var global3 = 0 ;

Use something like:

window.myGlobals = window.myGlobals || {} ;
myGlobals.global1 = 0 ;
myGlobals.global2 = 0 ;
myGlobals.global3 = 0 ;

That way you can do this:

/*global myGlobals:false */

Rather than having to do this:

/*global global1:false, global2:false, global3:false */

Which helps if you have a lot of globals...

View solution in original post

0 Kudos
2 Replies
Dale_S_Intel
Employee
378 Views

JSHint can be pickier than the browser, which is by design.  Fortunately there are a number of options to control it's behavior and solve problems like yours.

One would be to declare your globals in a comment like this:

/*jshint undef: true, unused: true */
/*global MY_GLOBAL */

 

You could also turn it off with:

//jshint undef:true

At least that's the what this site tells me.

EDIT: it is very important that there be no space between the opening comment marker and the jshint directives. Your jshint directives will be ignored if you do not follow this policy. Also, to make the /*global ... */ option easier to manage, put your globals inside a few objects, for example, rather than defining globals as:

var global1 = 0 ;
var global2 = 0 ;
var global3 = 0 ;

Use something like:

window.myGlobals = window.myGlobals || {} ;
myGlobals.global1 = 0 ;
myGlobals.global2 = 0 ;
myGlobals.global3 = 0 ;

That way you can do this:

/*global myGlobals:false */

Rather than having to do this:

/*global global1:false, global2:false, global3:false */

Which helps if you have a lot of globals...

0 Kudos
Adolfo_C_1
Beginner
377 Views

I didn´t understand at the first time but readding the JSHint documentation all be cleared. It´s really help. Thank you!

0 Kudos
Reply