javascript - run after the callback is finished -
i need run function after displaypredictionsuggestions
callback retrieves , stores result in global variable place
.
as understand callback runs asynchronously. can't sure callback finished when invoke console.log( json.stringfy( place ) );
how make sure program continues after callback finished (without nesting)?
predictionservice = new google.maps.places.autocompleteservice(); predictionservice.getplacepredictions({ input: '1 street, city' }, displaypredictionsuggestions ); displaypredictionsuggestions = function(predictions, status) { place = predictions[0]['place_id']; } console.log( json.stringfy( place ) );
you can avoid nesting callbacks using promises.
Comments
Post a Comment