I'm trying to modularize a JavaScript app using Require.js. I'm trying to figure out how to deal with global variables that are used in the app. Everything I read says that one of the points of Require.js is to get rid of global vars. Anyways I have a interactions like this:
function myFunction()
{
// Access some dynamic variables here
}
$('#myButton').on('click', myFunction());
mySettings = {};
$('#myForm').on('submit', function()
{
mySettings.someSetting = "someValue";
$.ajax(....) // Send the mySettings to some PHP script
}
So to sum up, the app is interactive and several controls and things users do on the page have to have access to the globally accessible variables and values and it has to be able to interact and do stuff with them.
Without global variables, how do I do this?