With reference to the code from here
With reference to the addListener(instance:Object, eventName:string, handler:Function) function. Here we pass in a handler. So toggleBounce is called when you click it.
I could also change it to var toggleFn = function toggleBounce() {....) and pass in toggleFn
My question is, can I pass in a function which takes parameters, for example if I wanted the handler to be a zoom(mapOptions.zoom -5) or similar function.
I know this is essentially a 'how do you pass functions as parameters' question but I just can't get it to work with different combinations.
function initialize() {
var mapOptions = {zoom: 13, center: stockholm };
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
marker = new google.maps.Marker({map:map,position: parliament });
google.maps.event.addListener(marker, 'click', toggleBounce);
}
function toggleBounce() {
if (marker.getAnimation() != null) { marker.setAnimation(null);}
else {marker.setAnimation(google.maps.Animation.BOUNCE);}
}