I'm studying some JS code and compared to other languages it's not making any sense to me. First, there's a date object that's declared and that I understand,
$ns.constant = {
date: {}, /* Input date */
};
Then there's functions like this one below where a date is passed to a function. Here's what I don't understand. In other languages, when you pass a variable to a function, that function creates a new variable that's local to the function and the function acts upon that local variable.
This function returns date.julian. But it also adds other dates like date.j2000 and date.1950. In my understanding of other languages, those aren't being returned because they're the date object local to the function. It would seem to me that in order to put those values into the date constant you'd have to return the entire date object the function created and not just date.julian. Or, is js just seeing that date being passed and somehow knows that it's the date constant?
Is this function modifying the date constant, an object that's local to the function or what?
Thanks
$ns.julian.calc = function (date) {
var centuries;
var year;
var month;
var b = 0;
var c;
var e;
year = date.year + 4800;
if (date.year < 0) {
year += 1;
}
month = date.month;
if (month <= 2) {
month += 12;
year -= 1;
}
e = Math.floor ((306 * (month + 1)) / 10);
centuries = Math.floor (year / 100);
if (date.year <= 1582) {
if (date.year == 1582) {
if (date.month < 10) {
b = -38;
}
if (date.month > 10 || date.day >= 15) {
b = Math.floor ((centuries / 4) - centuries);
}
}
else { b = -38; }
} else {
b = Math.floor ((centuries / 4) - centuries);
}
c = Math.floor ((36525 * year) / 100);
date.julianDate = b + c + e + date.day - 32167.5;
date.julianTime = (3600.0 * date.hours + 60.0 * date.minutes + date.seconds) / 86400.0;
date.julian = date.julianDate + date.julianTime;
date.j2000 = 2000.0 + (date.julian - $const.j2000) / 365.25;
date.b1950 = 1950.0 + (date.julian - $const.b1950) / 365.25;
date.j1900 = 1900.0 + (date.julian - $const.j1900) / 365.25;
return date.julian;
};