[Answered ]-Function invocation in javascript

2👍

Because you need to assign a function as a click handler – and you do that with…

google.maps.event.addListener(points[{{ marker.id }}], 'click',
function(){
    addInfoWindow(points[{{ marker.id }}])
});

… as this will create an anonymous function (with call to addInfoWindow in its body).

But with this…

google.maps.event.addListener(points[{{ marker.id }}], 'click',
    addInfoWindow(points[{{ marker.id }}])
);

… you try to assign the result of addInfoWindow call as event handler, not the function itself. Of course, it doesn’t work.

Leave a comment