Javascript - Calling a function in different file - JSLint error

Hello,
in a big php / javascript project I splitted my javascript function libraries to different files, like js_tools1.js, js_main2.js etc..

When I call a function from js_tools1.js out of js_main2.js, everything works fine.
But of course phpStorm shows JSLint and JSHint errors, becuase the function was not defined before used.
How do I do that? How do I tell a javascript function in file2 to use a function from file1 without any errors?

Thanks a lot, Adrian.

3 comments
Comment actions Permalink

If not already done, define your functions in namespaces (simple objects), then you can easily add them to the list of predefined variables in the JSHint options dialog or use JSHints global option:

/*global yournamespace, othernamespace */


Regards
Oliver

0
Comment actions Permalink

Hi Oliver,

you mean like this?

var myNamespace = function() {
     return {
          method1 : function() {
               // things
          },
          method2 : function() {
               // things
          }
     };
}();

Thanks a lot, Adrian.
0
Comment actions Permalink

It's also possible to specify wheather global variable names is readonly or not:

test:false, gl:true, k

test = 1; // error
gl = "x"; // ok
k = 0; // error


By default variable is readonly.

0

Please sign in to leave a comment.