Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Adolfo_C_1
Beginner
78 Views

Error warning in JS Hint problems

Jump to solution

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

Tags (2)
0 Kudos
1 Solution
Dale_S_Intel
Employee
78 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

2 Replies
Dale_S_Intel
Employee
79 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

Adolfo_C_1
Beginner
78 Views

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

Reply