I want to test google api. I created three files at once: index1.html , main.css , main.js
I connect everything at once into one html (fragment)
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script> <script> var map; function initialize() { map = new google.maps.Map(document.getElementById('map-canvas'), { zoom: 8, center: {lat: -34.397, lng: 150.644} }); } google.maps.event.addDomListener(window, 'load', initialize); </script> After I want to spread over the files. js I drop into the main.js file (I delete js in html and connect the link in place of the code). I'm testing - everything works.
Then I copy api and put a new file googl-api.js file, everything works (below is the structure)
<script src="googl-api.js"></script> <script src="main.js"></script> And now hocus pocus - I cut out the contents of the main.js file and insert googl-api.js at the end of the file and it does not work! What nonsense? I basically like what works in different files, but I can't figure out what's the catch? It seems so and so should work!
UPD
Error that is displayed in the browser console:
Uncaught TypeError: Cannot read property 'addDomListener' of undefined