admin管理员组文章数量:1026900
As in the application I need to have some configured variables which are to be global and I am using them across modules. My config file may look like.
config.js:
var config = {
baseServiceUrl: 'http://localhost/baseServiceUrl',
baseUrl: 'http://localhost/baseUrl',
mapping_764: {
location:'Austin',
emailAddress:'[email protected]',
registerLink:'/',
fbLikeLink:'.austin',
microSite: '/'
}
}
I am just loading this file using script tag along with requirejs.
<script src="js/app/config.js"></script>
<script data-main="js/main" src="js/libs/require/require.js"></script>
Now the global variable(object) config can be used in all the modules and also from browser console. So I was thinking what if someone changes this config attributes, the application is definitely going to crash because this config variable is used for service calls and for many other things.
Is there any way to handle this kind of issues.?
As in the application I need to have some configured variables which are to be global and I am using them across modules. My config file may look like.
config.js:
var config = {
baseServiceUrl: 'http://localhost/baseServiceUrl',
baseUrl: 'http://localhost/baseUrl',
mapping_764: {
location:'Austin',
emailAddress:'[email protected]',
registerLink:'https://www.customercare./en/austin/registration/',
fbLikeLink:'https://www.facebook./customercare.austin',
microSite: 'http://austin.customercare./'
}
}
I am just loading this file using script tag along with requirejs.
<script src="js/app/config.js"></script>
<script data-main="js/main" src="js/libs/require/require.js"></script>
Now the global variable(object) config can be used in all the modules and also from browser console. So I was thinking what if someone changes this config attributes, the application is definitely going to crash because this config variable is used for service calls and for many other things.
Is there any way to handle this kind of issues.?
Share Improve this question edited May 21, 2013 at 18:15 Steve P 19.4k7 gold badges72 silver badges96 bronze badges asked May 15, 2013 at 7:29 Sai ChaithanyaSai Chaithanya 7081 gold badge7 silver badges14 bronze badges1 Answer
Reset to default 5A couple things may help you:
First, for the pure "site configuration" (e.g. REST URLs) info, RequireJS has a configuration API. From the documentation:
requirejs.config({
config: {
'bar': {
size: 'large'
},
'baz': {
color: 'blue'
}
}
});
//bar.js, which uses simplified CJS wrapping:
//http://requirejs/docs/whyamd.html#sugar
define(function (require, exports, module) {
//Will be the value 'large'
var size = module.config().size;
});
There is also this question which addresses the general case of passing global variables around if you don't want to use the config API.
Second, for bootstrapping data into Backbone models, there is extensive discussion in this question
As in the application I need to have some configured variables which are to be global and I am using them across modules. My config file may look like.
config.js:
var config = {
baseServiceUrl: 'http://localhost/baseServiceUrl',
baseUrl: 'http://localhost/baseUrl',
mapping_764: {
location:'Austin',
emailAddress:'[email protected]',
registerLink:'/',
fbLikeLink:'.austin',
microSite: '/'
}
}
I am just loading this file using script tag along with requirejs.
<script src="js/app/config.js"></script>
<script data-main="js/main" src="js/libs/require/require.js"></script>
Now the global variable(object) config can be used in all the modules and also from browser console. So I was thinking what if someone changes this config attributes, the application is definitely going to crash because this config variable is used for service calls and for many other things.
Is there any way to handle this kind of issues.?
As in the application I need to have some configured variables which are to be global and I am using them across modules. My config file may look like.
config.js:
var config = {
baseServiceUrl: 'http://localhost/baseServiceUrl',
baseUrl: 'http://localhost/baseUrl',
mapping_764: {
location:'Austin',
emailAddress:'[email protected]',
registerLink:'https://www.customercare./en/austin/registration/',
fbLikeLink:'https://www.facebook./customercare.austin',
microSite: 'http://austin.customercare./'
}
}
I am just loading this file using script tag along with requirejs.
<script src="js/app/config.js"></script>
<script data-main="js/main" src="js/libs/require/require.js"></script>
Now the global variable(object) config can be used in all the modules and also from browser console. So I was thinking what if someone changes this config attributes, the application is definitely going to crash because this config variable is used for service calls and for many other things.
Is there any way to handle this kind of issues.?
Share Improve this question edited May 21, 2013 at 18:15 Steve P 19.4k7 gold badges72 silver badges96 bronze badges asked May 15, 2013 at 7:29 Sai ChaithanyaSai Chaithanya 7081 gold badge7 silver badges14 bronze badges1 Answer
Reset to default 5A couple things may help you:
First, for the pure "site configuration" (e.g. REST URLs) info, RequireJS has a configuration API. From the documentation:
requirejs.config({
config: {
'bar': {
size: 'large'
},
'baz': {
color: 'blue'
}
}
});
//bar.js, which uses simplified CJS wrapping:
//http://requirejs/docs/whyamd.html#sugar
define(function (require, exports, module) {
//Will be the value 'large'
var size = module.config().size;
});
There is also this question which addresses the general case of passing global variables around if you don't want to use the config API.
Second, for bootstrapping data into Backbone models, there is extensive discussion in this question
本文标签: javascriptHandling global varibales when using AMD RequirejsBackbonejsStack Overflow
版权声明:本文标题:javascript - Handling global varibales when using AMD Requirejs + Backbonejs - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745651437a2161343.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论