Javascript lets you use any Object as a Constructor Class. That's a
slightly odd design decision.
Many OOP languages make a clear distinction between Constructor Classes
and actual Objects, so when you attach a Method to something the
language parser knows whether its a Class Method or an Object Method
depending on what you're attaching it to.
Javascript can't guess from the context whether you want to create a
Class Method or an Object Method, so you have to use the .prototype
syntax to indicate that you want a Class Method.
This allows you to create as many application objects as you want.
var application1 = new MyApplication();
var application2 = new MyApplication();
Each of them have their own "this", so they can keep separate counts in
their own this.counter and have separate maps in their own this.map. If
the "this" belonged to the parent MyApplication object, then both
application1 and application2 would share the same MyApplication.counter
and MyApplication.map, which is not usually what we want.
In this particular case, things happen to go horribly wrong if you
create two MyApplication objects, because they both create a GMap2() in
the same div, but we can fix that:
function MyApplication(myDiv) {
this.counter = 0;
this.map = new GMap2(document.getElementById(myDiv));
this.map.setCenter(new GLatLng(37.4419, -122.1419), 13);
GEvent.bind(this.map, "click", this, this.onMapClick);
}
var application1 = new MyApplication("map_canvas");
var application2 = new MyApplication("map_canvas2");
--
Mike Williams
http://econym.org.uk/gmap
--
You received this message because you are subscribed to the Google Groups
"Google Maps API" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-api?hl=en.