JSLint - problems importing packages

I am using a java script using rhino. I have several classes written in java that I import into javascript.

But, when I check the javascript against JSLint, it invalidates the javascript saying:

Line 9 character issue: "importPackage" was used before it was defined.

Here's an example from my script:

importPackage(Packages.org.raj.test);
var test = "123";

      

I chose the option "Assume Rhino", but still it encountered the same error.

How can I solve this problem?

Note that the ECMA standard does not cover communication with Java (or with any external object system, for that matter).

+3


source to share


2 answers


I have explicitly added the following line on top of my script

/ * global importPackage: true * /

and it works!



+1


source


It looks like the "Assume Rhino" flag (aka rhino: true

in an options directive) predefines several globals for you, rather importPackage

than being one of them. You can see the complete list in the code .

Paul's answer is basically the right workaround - you just manually declare every additional global you use. This code passes JSLint cleanly:



/*global importPackage, Packages */
importPackage(Packages.org.raj.test);
var test = "123";

      

+1


source







All Articles