So I have recently started at a new place of employment and I have run across a format of javascript which makes me question its purpose. ( in particular the brackets {})
var _occurrences = getOccurrences($('#ddlTours').val());
{
var _occurrence = getObjectByValue(_occurrences, 'tourID', booking.tourID);
{
_occurrenceID = _occurrence.occurrenceID;
}
}
To me it almost looks like an attempted object construction. i.e.
var _occurrences : // Ignoring = getOccurrences($('#ddlTours').val());
{
_occurrence : // Ignoring getObjectByValue(_occurrences, 'tourID', booking.tourID);
{
_occurrenceID : _occurrence.occurrenceID;
}
}
But as I understand it will execute it like.
var _occurrences = getOccurrences($('#ddlTours').val());
var _occurrence = getObjectByValue(_occurrences, 'tourID', booking.tourID);
_occurrenceID = _occurrence.occurrenceID;
Or is it so _occurrence gets delete and does not sit around as its encapsulated and we assign a var that outside of the encapsulation. Does that actually work as a performance improvement? i.e.
Global var a = 1
{
b = someFunction() // After execution because of encapsulation it poofs???
for(var c in b)
{
a += c.somefunction()
}
}
Another option is that its just bad code?
Or perhaps its meant as a logical separation of code to help the dev?
I was just wondering if someone could shed some light on this for me :)