Sun*_*nny 2 javascript model-view-controller google-maps-api-3 google-maps-markers
我正在查看Google Maps API MVC用法示例.请参阅https://developers.google.com/maps/articles/mvcfun?csw=1
在第一个简单示例中,我无法理解marker.bindTo()调用.bindTo()实际上是MVC对象的一种方法(请参阅https://developers.google.com/maps/documentation/javascript/reference#MVCObject).marker本身不是MVC对象,而是具有MVC对象作为其原型的对象的属性.那么这个bindTo方法如何作为标记的属性关联?
可能是我在这里缺少的基本内容!
谢谢你的任何解释.
/**
* 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();
Run Code Online (Sandbox Code Playgroud)
MVCObject构造函数保证是一个空函数,所以你可以通过编写MySubclass.prototype = new google.maps.MVCObject()来继承MVCObject;
该技术也将用于google.maps.Marker实例.
在构造一个的google.maps.Marker-instance是的构造google.maps.MVCObject-instance,所以标记将有MVCObject的方法
这样的实例google.maps.Marker基本上是MVCObject扩展了的属性/方法google.maps.Marker-prototype