Non-inline function as argument
3 Message(s) by 2 Author(s) originally posted in javascript
| From: bodorange |
Date: Thursday, November 23, 2006
|
I'm not sure if this is a JAVAscript question or more google maps
API (application
programming interface)
specific. I'm new to both JAVAscript and
Google maps and find the
code less
readable if I use
inline function s. How do I use GEvent.addListener() with
say a
reference to a function (or similar) as an
argument rather than an
inline function as the argument? How can I call something like
GEvent.addListener(map, '
click ', map_click(point));
function map_click(aPoint){
.
.
}
Thanks for any help.
| From: David Golightly |
Date: Sunday, November 26, 2006
|
wrote in message:
I'm not sure if this is a JAVAscript question or more google maps API (application programming interface)
specific. I'm new to both JAVAscript and Google maps and find the code less
readable if I use inline functions. How do I use GEvent.addListener() with
say a reference to a function (or similar) as an argument rather than an
inline function as the argument? How can I call something like
GEvent.addListener(map, 'click', map_click(point));
function map_click(aPoint){
.
.
}
Thanks for any help.
That's easy:
function map_click(aPoint) {
// do something
}
GEvent.addListener(map, 'click', map_click); // just use the fn name,
no parens
is for your purposes the same as
GEvent.addListener(map, 'click', function(aPoint) {
// do something
});
Note that you must pass the function as a reference, that is, without
the parens. The click
event will call this function, passing in
arguments as necessary.
-David
| From: bodorange |
Date: Sunday, November 26, 2006
|
wrote in message:
wrote in message:
I'm not sure if this is a JAVAscript question or more google maps API (application programming interface)
specific. I'm new to both JAVAscript and Google maps and find the code less
readable if I use inline functions. How do I use GEvent.addListener() with
say a reference to a function (or similar) as an argument rather than an
inline function as the argument? How can I call something like
GEvent.addListener(map, 'click', map_click(point));
function map_click(aPoint){
.
.
}
Thanks for any help.
That's easy:
function map_click(aPoint) {
// do something
}
GEvent.addListener(map, 'click', map_click); // just use the fn name,
no parens
is for your purposes the same as
GEvent.addListener(map, 'click', function(aPoint) {
// do something
});
Note that you must pass the function as a reference, that is, without
the parens. The click event will call this function, passing in
arguments as necessary.
-DavidMany thanks for the help.
Cheers.
Next Message: RSS Ticker on Webpage