On Jul 21, 6:21 am, SteveYoungGoogle <[email protected]>
wrote:
> When adding a listener why does the third element of the argument,
> which is always a handler function, have to be named as a function
> every time as in:
>
> google.maps.event.addListener(map, 'click', function() {
> alert("hello")
>
> });
>
That syntax returns a pointer to an anonymous function.
> Why can’t you just assume it’s a function and use the more compact?
This is javascript, nothing specific to the Google Maps API.
>
> google.maps.event.addListener(map, 'click', alert("hello"));
'alert("hello")' is executed and its return value (null) is used as a
function pointer which is executed when the 'click' event happens.
-- Larry
>
> After all we know that the second element is an event but we don't
> have to write event: 'click', just 'click'
>
> Just curious, Steve.
--
You received this message because you are subscribed to the Google Groups
"Google Maps JavaScript API v3" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-js-api-v3?hl=en.