> > From: Michael Geary
> > Just to be clear, main.js doesn't define a "()" function,
> > it defines an *anonymous* function, and you can have
> > as many of those as you want.
> >
> > For example, this is perfectly legal:
> >
> > (function() {
> > // code here
> > })();
> >
> > (function() {
> > // more code here
> > })();
> >
> > It's just as if you had written:
> >
> > function a() {
> > // code here
> > }
> > a();
> >
> > function b() {
> > // more code here
> > }
> > b();
> From: bratliff
> Thanks for the clarification. I think I understand it now.
> In your second example, both "a" & "b" will be added into the
> global name space but "(function(){ ... })();" is able to suppress it.
That's right, in the "(function(){ ... })();" case, the function doesn't
even have a name, so nothing is added to the global namespace.
Just to take another example, we're all familiar with using anonymous
functions like this:
setTimeout( function() {
// code here
}, 1000 );
Or:
GEvent.addListener( marker, 'click', function() {
// code here
});
Those anonymous functions are just like the one used in the "(function(){
... })();" notation. You can have as many of them as you want and they are
all independent of each other. The only difference with the "(function(){
... })();" notation is that it creates an anonymous function and then calls
it immediately because of the () at the end.
> Slightly off topic, it is too bad neither VML nor CANVAS has
> the ability to cache the building of the same shape from a
> previous run.
Very true. PolyGonzo does a bit of caching here to partially make up for
this. When it runs the loop to convert the lat/longs to pixel positions, it
saves the results for each zoom level. If you pan the map, or zoom in or out
and then return to the same zoom level again, it doesn't recalculate the
pixel positions but uses the ones it has already calculated.
-Mike
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---