I have two js file in my html page . If the first one begins with :
(function($){
..
..
}(jQuery));
can I insert a var into function($,varname) , return it's value and use it in the other file?
You need a global variable for this. You can do this in one of a few ways. Let's assume we need to send the value "Bacon" to the other script.
(function($){
window.myScriptsExports = "Bacon";
}(jQuery));
// OR
var myScriptsExports = (function($){
// other code
return "Bacon";
// NO other code
}(jQuery));
// OR (not really recommended)
(function($){
// other code
$.myScriptsExports = "Bacon";
// other code
}(jQuery));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With