Recently I saw something like this in some code from a project I'm working on...
var domObjects = {
$body: $('body'),
$someDiv: $('.some-div'),
$someOtherDiv: $('.some-other-div')
}
var constants = {
CONST_ONE: 'some value',
CONST_TWO: 'some value',
CONST_THREE: 'some value'
}
As you already may notice this code intents to replace code like this:
var $body = $('body'),
$someDiv = $('.some-div'),
$someOtherDiv = $('.some-other-div');
var CONST_ONE = 'some value',
CONST_TWO = 'some value',
CONST_THREE = 'some value';
The idea behind this is to wrap the variables in a more "semantic" object so it could be easier to use, but I really have my doubts about to create an object just for cosmetic reasons.
- It this ok?
- There is any real advantage if I do the declarations this way?
- There is any disadvantage?