This function is being called with two parameters:
ds.route()
The first parameter is an object with some values in it:
{
origin: $('#from').val(),
destination: $('#to').val(),
travelMode: $('#mode').val()
}
The second parameter is a function:
function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
fitBounds = true;
dr.setDirections(result);
}
else {
$('#error').text(status).show();
}
recalcHeight();
}
Note that in JavaScript a function is an object like any other, and can be passed around like a variable. Since it's being passed into ds.route() as a variable, the function itself isn't being executed yet.
Internally, ds.route() is using the first parameter which has the values (origin, destination, travelMode) to do, well, something. It doesn't matter what, it's just whatever that function does.
Then, when it's done, it's going to execute the second parameter, which is the function. When it executes that function, it's going to pass two values into it as parameters. Those values will end up being the result and status variables used within the function.
To illustrate, you could do something as simple as this:
function doSomething(value, callback) {
if (value == 1) {
alert("The value is 1");
callback(2)
}
}
doSomething(1, function (value) {
if (value == 2) {
alert("The value is 2");
}
});
This defines a function which takes two arguments, and expects them to be a number and a function. If the number equals 1, it executes that function. This function is then called with the value 1 and a function, which will be executed as a callback.