我有下面的功能。除了 Push、Pop 和 Remove 方法外,一切正常。这些方法应该由事件处理程序调用。此事件由 google maps api 触发。
问题是当事件被触发时,这些方法都找不到。我有“推送未定义”错误消息。
我试过了,但这不起作用。
如何从事件处理程序调用公共方法?
多谢你们
function Track(mapContainer) {
var map = mapContainer;
var points = new Array();
var isEditMode = false;
var clickListener;
this.Push = function(point) { ... }
this.Pop = function() { ... }
this.Remove = function(point) { ... }
//Enable / disable the marker placements
this.PlaceWaypoint = function(isPlacing) {
if (isPlacing != true) {
if (clickListener != null) {
google.maps.event.removeListener(clickListener);
clickListener = null;
}
} else {
clickListener = map.AddEvent("click", function(event) {
if (!IsDoubleClick()) {
var point = map.PlaceMarker(new WayPoint(event.latLng))
point.RemoveListener(function() { Remove(point); });
Push(point);
} else {
Pop();
}
});
}
}
}