I'm just wondering if it's fine to declare variables with JSON format?
For example, do this:
$(function(){
var global = {
varA : 'This is a global variable from global.varA ~!',
varB : 'This is a global variable from global.varB ~!'
};
alert(global.varA);
alert(global.varB);
});
Instead of this:
$(function(){
var globalVarA = 'This is a global variable from globalVarA ~!',
globalVarB = 'This is a global variable from globalVarA ~!';
alert(globalVarA);
});
- The reason why I want to do this is that, It would be easier to look for when I work on a really long JS file. And anything starts with
global.I know it is a global variable. - Is it a good practice?
- Is there anything I need to put into considerations?
globalwhose value is an object. edit: Oh you are asking whether it's "fine". Yes it is ;)