javascript - Handling global varibales when using AMD Requirejs + Backbonejs -


as in application need have configured variables global , using them across modules. config file may like.

config.js:

var config = {     baseserviceurl: 'http://localhost/baseserviceurl',     baseurl: 'http://localhost/baseurl',      mapping_764: {             location:'austin',             emailaddress:'austin@customerservice.com',              registerlink:'https://www.customercare.com/en/austin/registration/',             fblikelink:'https://www.facebook.com/customercare.austin',             microsite: 'http://austin.customercare.com/'         } } 

i loading file using script tag along requirejs.
<script src="js/app/config.js"></script>
<script data-main="js/main" src="js/libs/require/require.js"></script>

global variable(object) config can used in modules , browser console. thinking if changes config attributes, application going crash because config variable used service calls , many other things.

is there way handle kind of issues.?

a couple things may you:

first, pure "site configuration" (e.g. rest urls) info, requirejs has configuration api. the documentation:

requirejs.config({     config: {         'bar': {             size: 'large'         },         'baz': {             color: 'blue'         }     } });  //bar.js, uses simplified cjs wrapping: //http://requirejs.org/docs/whyamd.html#sugar define(function (require, exports, module) {     //will value 'large'     var size = module.config().size; }); 

there this question addresses general case of passing global variables around if don't want use config api.

second, bootstrapping data backbone models, there extensive discussion in this question


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -