I didn't see the original version of your code, but I can assure you that it
is perfectly OK to write JavaScript code like this:
<script type="text/javascript">
foo();
function foo() {
alert( 'bar' );
}
</script>
The browser processes function statements before executing your code, so
even though we call foo() before the definition (in terms of source
location), the function statement has already been processed and the
function is ready to be called.
This is also OK:
<script type="text/javascript">
outer();
function outer() {
foo();
function foo() {
alert( 'bar' );
}
}
</script>
But this is *not* OK:
<script type="text/javascript">
outer();
function outer() {
if( true ) {
foo();
function foo() {
alert( 'bar' );
}
}
}
</script>
The difference is that the function statement defining foo is now inside an
if statement, which would be illegal, except that different browsers
"support" this in different ways. It may work as you expect in one browser
but not another (because it really shouldn't work at all).
A function statement may only appear in the global scope or directly inside
another function. It may not appear nested inside an if statement, for
loop, or any other block. Perhaps that was the problem in the original code?
If you happen to still have a copy of it, I can tell you exactly what the
problem was.
-Mike
On Tue, Jul 13, 2010 at 10:48 AM, redvibes <[email protected]> wrote:
> It worked - thank you. I'm kinda new to javascript, and it occured
> strange to me that functions are declared after being used in the
> code, but I've seen this in a few examples (even in maps API), so I
> thought that this is a proper routine.
>
> Once again, thank you.
>
> On 13 Lip, 13:33, Andrew Leach <[email protected]> wrote:
> > On 13 July 2010 12:17, redvibes <[email protected]> wrote:
> >
> > > Unfortunately this function doesn't work in Firefox. Console displays
> > > an error message: createListener is not defined. Is there any known
> > > issue related to Firefox?
> >
> > >http://redvibes.pl/slovenia/index_pl.php?s=wyprawathere should be
> > > several markers on the map...
> >
> > Move your function createListener so that it's defined before it's
> > actually called. It needs to be defined in global scope, so *between*
> > these two lines would be a good place:
> >
> > <script type='text/javascript'>
> > function mapaStart()
> >
> > Internet Explorer parses all the Javascript before it calls anything,
> > so it will already have found the function. Firefox needs to have
> > encountered the function before it's called.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Maps API" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-maps-api%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-maps-api?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Google Maps API" 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-api?hl=en.