问题
This may not be the best place for this question but here goes:
I'm a beginner in googlemaps and javascript and found this example for something I'm working on. http://search.missouristate.edu/map/mobile/examples/ZoomPanControl.htm I understand most of the code but I'm having a hard time finding out the meaning of the following lines of code at the end of this file ZoomPanControl.js
window["missouristate"] = window["missouristate"] || {};
window["missouristate"]["web"] = window["missouristate"]["web"] || {};
window["missouristate"]["web"]["ZoomPanControl"] = ZoomPanControl;
Edit: The original example is no longer available and redirects to a map that doesn't have the custom ZoomPanControl, here is an example that shows the custom zoom/pan control referenced
回答1:
It's appending the control to the global variable(or namespace?) 'window', so that you can instantiate it using:
var ZoomPanControl = new missouristate.web.ZoomPanControl(map);
The Google Maps API loader does the same thing, namely:
window.google = window.google || {};
google.maps = google.maps || {};
来源:https://stackoverflow.com/questions/12149305/googlemaps-api3-demogallery-example-custom-small-navigation-control