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.
Please sign in to leave a comment.
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:
Regards
Oliver
Hi Oliver,
you mean like this?
var myNamespace = function() { return { method1 : function() { // things }, method2 : function() { // things } }; }();It's also possible to specify wheather global variable names is readonly or not:
By default variable is readonly.