I'm having trouble with the following code snippet. My init method needs to run and complete the getLocation() function before the initializeMapp() and geoListen() can run. I have rsvp.js linked as a resource, but not quite sure how to implement. I also tried the jQuery $when.done method. Any help is appreciated.
jQuery Method:
//initial page load method
function init() {
//get user location then builds map and listens to database
$.when(getLocation()).done.(function () {
//build map now that you have user location
initializeMap();
//Starts listening to database changes
geoListen();
})
}
RSVP method:
//initial page load method
function init() {
//get user location then builds map and listens to database
getLocation().then(function () {
//build map now that you have user location
initializeMap();
//Starts listening to database changes
geoListen();
})
}
you can make your
getLocation
function accept callbacks and execute them whengetLocation
finishesor you can pass an array of callback references and loop through them in
getLocation
and call themalternatively you can use Q.js and return a promise from
getLocation