- This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
Viewing 2 posts - 1 through 2 (of 2 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › Require JS and global variables
I’m writing an application that could use some organizing and seperation (I think).
I’ve looked to RequireJS for this.
If I have two modules that will be using the same group of “global” variables, how do I set things up to allow this? The only way I can think of doing the global variable between multiple modules is to also create a module FOR the variables.
I have a feeling that I’m overthinking things are setting up my modules incorrectly. Here is a module for example:
var DrawScript = function(){
var DRAW = 0,
SELECT = 1,
SCROLL = 2;
var MOUSEBUTTONS = {
'S': 83,
'C': 67,
'D': 68,
'DELETE': 46,
'BACKSPACE': 8
};
var init = function(){
console.log("started");
};
return {
init: init
};
}();
Now, how do I use the MOUSEBUTTONS variable in another module without return it as well? I have quite a few other global variables I’m using within this module, so returning them all seems extreme. Maybe not though, hence this post :)
Check out the requirejs.config()
method (which can be used to pass data “down” to modules in your app):
http://requirejs.org/docs/api.html#config-moduleconfig
Some more discussion:
http://stackoverflow.com/questions/9916073/how-to-load-bootstrapped-models-in-backbone-js-while-using-amd-require-js/10288587#10288587
Cheers