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

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -