You may be worried about a problem that doesn't exist. Every time you call a
function, JavaScript creates a new, unique set of local variables for that
invocation of the function. It doesn't reuse the same function invocation
and its local variables over and over again.

Now, you *could* write code that would get you in trouble here. For example,
you could use global variables instead of local variables in your function,
and those would get overwritten as you might expect.

But normal JavaScript behavior does exactly what you want here. This is true
for plugin methods just like any other functions.

As Shawn suggested, if you have trouble with a specific bit of code, post a
link to it and someone can take a look at it.

-Mike

> From: howardk
> 
> Is there a way of instantiating multiple instances of a 
> plugin on the same page?
> 
> What I have essentially is an animated effects plugin, and I 
> want to be able to invoke separate instantiations of it, 
> doing something like the following:
> 
> <script>
>       $( '#effect_1' ).animEffect( { name: 'jumper', color: 
> 'ff0000', fps:
> 30 } );
>       $( '#effect_2' ).animEffect( { name: 'round-the-moon', color:
> 'ffff00', fps: 40 } );
> </script>
> 
> <div id='effect_1'></div>
> <div id='effect_2'></div>
> 
> I'm still fairly new to javascript. As far as I can tell 
> though, it looks like it can't be done, since as far as I can 
> see, each plugin invocation is really calling the same 
> function object over and over again (thereby overwriting 
> whatever instance or local variables might have been set in a 
> prior invocation).
> 
> Is this correct? Is there a way of doing this, or am I out of luck?
> Howard
> 

Reply via email to