I am pulling my hair out over this one. I have functions defined in separate files both loaded with wp_enqueue_scripts. In each file I wrap the functions between
(function($){
})(jQuery);
The problem is when I try to call one function that is defined in a different file I get "The function xxxx is not defined" I verified that the scripts are loaded in the correct order and that there are no errors. I can call the function within the same file and it works alright but when I try to call it from a different file it doesn't. Is there some sort of "Namespace" or something that I am missing?
EDIT: I understand what is going on... When I declare a function inside the (function($)... it is not in the global scope. If I define the function outside of it I can access it. So my question is how do I define a function in the global scope from within the (function($)..?
EDIT 2: OK I got something working. I found out if I declare the function like:
ShowForm = function(url){
...
}
instead of
function ShowForm(url){
...
}
it works. Can anyone explain to me why I have to declare the function this way? Is there an alternative way to define the function so it is available in the global scope?