我定義這個類:如何從其方法內的回調函數訪問對象屬性?
function GMap(map, marker, geocoder) {
this.map = map;
this.marker = marker;
this.geocoder = geocoder;
this.setMarker = function(address) {
this.geocoder.geocode({'address' : address}, function(results, status) {
map.setCenter(results[0].geometry.location);
marker.setPosition(results[0].geometry.location);
});
}
}
你怎麼能在回調函數訪問GMAP的map
和屬性?
非常感謝。
我正在傳遞地圖和標記來做依賴注入=>全局變量在「可測試代碼」中是被禁止的。 :) http://www.youtube.com/watch?v=acjvKJiOvXw – Toto 2010-08-14 17:33:40