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

Discussion in 'Javascript' started by hemant.singh@gmail.com, Apr 23, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

  2. Randy Webb Guest

    Re: Problem of duplicate function names: When 2 same type of JS loadedin 1 Page

    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/
    Randy Webb, Apr 23, 2006
    #2
    1. Advertising

  3. 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
    Thomas 'PointedEars' Lahn, Apr 23, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marcelo Birnbach [MS]
    Replies:
    0
    Views:
    3,308
    Marcelo Birnbach [MS]
    Jun 28, 2003
  2. Udo Corban
    Replies:
    0
    Views:
    3,826
    Udo Corban
    Jan 23, 2004
  3. Replies:
    0
    Views:
    440
  4. Lewis G. Pringle, Jr.
    Replies:
    0
    Views:
    591
    Lewis G. Pringle, Jr.
    Sep 30, 2003
  5. Replies:
    1
    Views:
    665
    Alessandro Zifiglio
    Jul 18, 2006
Loading...

Share This Page