If I understand this correctly, using defer will load the scripts in the order I put them.
This will allow me to load jQuery before my own function (because it's lighter and laods more quickly). I load Google Maps at the bottom because it has a callback to a function inside tv-modal.js.
<script src="js/jquery.min.js" defer></script>
<script src="js/tv-modal.js" defer></script>
<script src="https://maps.googleapis.com/maps/api/js?key=abc&callback=modalMap.initMap" defer></script>
My Js looks like this:
var modalMap = {
map: null,
init: function() {
var self = this;
this.map = $('#modal-g-map');
},
initMap: function(){
map = new google.maps.Map(document.getElementById('modal-g-map'), {
center: {lat: 59.9071401, lng: 10.7711175},
zoom: 11
});
}
}.init();
But Google Map isn't happy:
Uncaught InvalidValueError: modalMap.initMap is not a function
Why can't Google Maps callback call my function modalMap.initMap?
&callback=myfunctionwhich itself just callsmodalMap.initMap();?