I've got a javascript/jQuery function called addLocation, which is a method of an object literal:
addLocation: function(latLng, address=false, elevation=false, pan=false)
{
$.when(geographic.getAddress(latLng), geographic.getElevation(latLng), geographic.getMagneticDeclination(latLng))
.done(function(data){
if (data.status != 'OK') {
window.alert(data.message);
}
if (pan) {
flyityourself.map.panTo(latLng);
flyityourself.map.setZoom(16);
}
flyityourself.addWaypoint(latLng, data);
flyityourself.addMarker(latLng, data);
})
.fail(function(msg) {
window.alert(msg);
}
);
},
The three functions getAddress, getElevation and getMagneticDeclination are all methods of a second object literal named 'geographic'.
But the code is failing.
In the debugger, I have checked all four functions.
- Each of getAddress, getElevation and getMagneticDeclination create $.Deferred objects and return $.Deferred.promise objects as they should.
- Each of getAddress, getElevation and getMagneticDeclination are retrieving the right data and are all reaching their respective resolve() statements.
- But in addLocation(), the data parameter only contains the data returned from getAddress.
Previously, only the three methods getAddress, getElevation and getMagneticDeclination were in the object literal 'geographic'. addLocation was in a flat .js file. In this case the code worked.
But since changing my code to put addLocation inside an object literal, the code has started to fail.
Does $.when work differently in object literals or have I forgotten to qualify something?
Regards. Chris B.