467,146 Members | 1,030 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,146 developers. It's quick & easy.

Problem of duplicate function names: When 2 same type of JS loaded in 1 Page

I am stuck with strange JS issue

My product gives user to show some images(which track mouseover) on
page by embedding script like
<script src=http://domain.com/GetDynamicJS?domagic=1>
</script>

Now user is embedding more than of the above and when user mouse over's
the image output of first1 than function getting called is script
loaded in last ... thus error, as that script don't have the relevant
data for it ...
Any solution for ?
Following possible solutions look feasible to me?
1) Somehow I get a static variable and all the JS loaded from my domain
will keep data in that static variable, how to implement it, im not
sure :)
2) This is crude, but how about I dynamically give method names of
events in script such that there are no duplicate function names, but
this will again bring lot of other complexity and might need usuage of
eval which is evil and I'll look some option for not using it rather
TIA

Apr 23 '06 #1
  • viewed: 1296
Share:
2 Replies
he**********@gmail.com said the following on 4/23/2006 12:16 AM:
I am stuck with strange JS issue

My product gives user to show some images(which track mouseover) on
page by embedding script like
<script src=http://domain.com/GetDynamicJS?domagic=1>
</script>
Your script tag isn't close to any form of valid HTML but ok.
Now user is embedding more than of the above and when user mouse over's
the image output of first1 than function getting called is script
loaded in last ... thus error, as that script don't have the relevant
data for it ...
"more than of the above"? Are they including more than one copy or more
scripts than just yours?
Any solution for ?
Following possible solutions look feasible to me?
1) Somehow I get a static variable and all the JS loaded from my domain
will keep data in that static variable, how to implement it, im not
sure :)
The response to that depends on the answer to my question above.
2) This is crude, but how about I dynamically give method names of
events in script such that there are no duplicate function names, but
this will again bring lot of other complexity and might need usuage of
eval which is evil and I'll look some option for not using it rather


eval is evil indeed but eval is not needed to access dynamically named
functions.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 23 '06 #2
he**********@gmail.com wrote:
My product gives user to show some images(which track mouseover) on
page by embedding script like
<script src=http://domain.com/GetDynamicJS?domagic=1>
</script>

Now user is embedding more than of the above and when user mouse over's
the image output of first1 than function getting called is script
loaded in last ... thus error, as that script don't have the relevant
data for it ...
A second FunctionDeclaration for the same identifier creates a new Function
object and replaces the former reference with a reference to the new
object. Are you having that problem?
Any solution for ?
It is not clear why the user would include the same code twice, particularly
because you have showed none of it (not even a URL). The only reason I can
think of is that what is generated here does not contain only "static"
FunctionDeclarations. So the most reasonable approach would be to have one
resource serving the "static" declarations, and another one serving
the "dynamic" code.
Following possible solutions look feasible to me?
1) Somehow I get a static variable and all the JS loaded from my domain
will keep data in that static variable, how to implement it, im not
sure :)
There is no such thing as a static variable, ECMAScript implementations in
HTML UAs do not provide such an attribute for its identifiers. However, if
the "static" part of the code defined an common object, and the "dynamic"
part would add properties to that object, overwriting one property value
with another could be avoided. An Object object or an Array object could
serve that purpose.
2) This is crude, but how about I dynamically give method names of
events in script such that there are no duplicate function names, but
this will again bring lot of other complexity and might need usuage of
eval which is evil and I'll look some option for not using it rather


Probably not. However, it is difficult to come up with helpful suggestions
without knowing what exactly is going on.

Have a look at <URL:http://pointedears.de/hoverMe> (Read the Source, Luke).
PointedEars
Apr 23 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by JKop | last post: by
15 posts views Thread by Hemant Shah | last post: by
2 posts views Thread by ajikoe@gmail.com | last post: by
19 posts views Thread by Larry Smith | last post: by
5 posts views Thread by althafexcel@gmail.com | last post: by
11 posts views Thread by =?ISO-8859-1?Q?Jean=2DFran=E7ois_Michaud?= | last post: by
10 posts views Thread by DavidPr | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.