2

I'm trying to pass arguments inside google.maps.event.addListener

I know I can do it like this

google.maps.event.addListener(marker, 'mouseover', function() {
    callback(param1, param2);
});

but since I'm declaring markers inside a loop, I'm getting linting errors :

Dont make functions within a loop

I tried adding them like this:

google.maps.event.addListener(country, 'mouseover', toggleOpacity, param1, param2);

but it's not working ..

Anyone knows how I can pass arguments without making use of a second function ?

AlexB
  • 7,302
  • 12
  • 56
  • 74
Mihnea Belcin
  • 554
  • 3
  • 10
  • possible duplicate of [Pass parameter to callback function](http://stackoverflow.com/questions/1663309/pass-parameter-to-callback-function) – geocodezip Jun 02 '14 at 14:27
  • dont think so . that should be fixed by passing this.id forward . i cant add function() {} there because of linting ... – Mihnea Belcin Jun 02 '14 at 14:29
  • Well your second attempt `google.maps.event.addListener(country, 'mouseover', toggleOpacity, param1, param2);` isn't going to work because executes the function and uses the return value as a function pointer to a function to call on the mouseover event. – geocodezip Jun 02 '14 at 14:31
  • possible duplicate of [How can I pass a parameter to a function without it running right away?](http://stackoverflow.com/questions/9638361/how-can-i-pass-a-parameter-to-a-function-without-it-running-right-away) – geocodezip Jun 02 '14 at 14:36

0 Answers0