Monday, May 20, 2024
147
rated 0 times [  151] [ 4]  / answers: 1 / hits: 5428  / 10 Years ago, tue, april 15, 2014, 12:00:00

I am looking at the Google Maps API MVC usage example. See https://developers.google.com/maps/articles/mvcfun?csw=1



In the first simple example, I am unable to understand the marker.bindTo() call. The bindTo() is actually a method of the MVC object (See https://developers.google.com/maps/documentation/javascript/reference#MVCObject). marker itself is not an MVC object but a property of an object that has a MVC object as its prototype. So how is this bindTo method associated as a property of marker?



May be something elementary that I am missing here!



Thanks for any explanation.



    /**
* A distance widget that will display a circle that can be resized and will
* provide the radius in km.
*
* @param {google.maps.Map} map The map on which to attach the distance widget.
*
* @constructor
*/
function DistanceWidget(map) {
this.set('map', map);
this.set('position', map.getCenter());

var marker = new google.maps.Marker({
draggable: true,
title: 'Move me!'
});

// Bind the marker map property to the DistanceWidget map property
marker.bindTo('map', this);

// Bind the marker position property to the DistanceWidget position
// property
marker.bindTo('position', this);
}
DistanceWidget.prototype = new google.maps.MVCObject();

More From » model-view-controller

 Answers
4

The description may be found at the documentation of MVCObject:



The MVCObject constructor is guaranteed to be an empty function, and so you may inherit from MVCObject by simply writing MySubclass.prototype = new google.maps.MVCObject();



This technique will also be used for a google.maps.Marker-instance.



The constructor of a google.maps.Marker-instance is the constructor of a google.maps.MVCObject-instance, so a Marker will have the methods of a MVCObject



So the instance of a google.maps.Marker basically is an MVCObject extended with properties/methods of the google.maps.Marker-prototype


[#46007] Monday, April 14, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lailab

Total Points: 706
Total Questions: 102
Total Answers: 95

Location: Falkland Islands
Member since Mon, Jul 13, 2020
4 Years ago
;