I have this code:
(function ($) {
$(document).ready(function() {
test("hola","caracola");
});
function test(somevar1, somevar2)
{
alert(somevar1+ "" + somevar2);
}
}(jQuery));
function atest2(somevar1, somevar2)
{
test(somevar1+ "" + somevar2);
}
when executing test2 function the result is:
ReferenceError: test is not defined
My question is:
How can I call test2 to execute correctly jQuery’s inner test function?
Thanks
You have to export
testto the global scope if you want to use it outside the anonymous function. That can be done in ths way:The big advantage of this method over moving the function declaration outside the anonymous function is that
testcan still use local variables, which are only accessible from within the anonymous function.