setTimeout and passing argument

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Raphael Bauduin

    #1

    setTimeout and passing argument

    Hi,

    I'm working with mozilla, building a little XUL app.
    I have a datasource, and want to display a message
    once it is loaded (datasource.loa ded is true).

    So, I thought to use timouts, but as the code to execute is
    passed as a string, I cannot pass local variable to this code.

    Anyone has a suggestion?

    Thanks.

    Raph

    Here is what I wanted to do (but I can't pass the datasource as argument):

    setTimeout(chec k_if_loaded(dat asource), 500)


    with this function:

    function check_if_loaded (a_ds)
    {
    if (!datasource.lo aded)
    {
    setTimeout(chec k_if_loaded(dat asource), 500)
    }


    }

  • Jim Ley

    #2
    Re: setTimeout and passing argument

    On Wed, 05 Nov 2003 15:55:28 +0100, Raphael Bauduin
    <raphael.baudui n@be.easynet.ne t> wrote:
    [color=blue]
    >I'm working with mozilla, building a little XUL app.
    >I have a datasource, and want to display a message
    >once it is loaded (datasource.loa ded is true).[/color]

    I imagine it'll throw an event at such a time, catch that event, don't
    test datasource.load ed is true at intervals, in fact if the technology
    does require you to do this, walk away now, the technology is flawed
    it should be event driven.

    Jim.
    --
    comp.lang.javas cript FAQ - http://jibbering.com/faq/

    Comment

    • Raphael Bauduin

      #3
      Re: setTimeout and passing argument

      Jim Ley wrote:[color=blue]
      > On Wed, 05 Nov 2003 15:55:28 +0100, Raphael Bauduin
      > <raphael.baudui n@be.easynet.ne t> wrote:
      >
      >[color=green]
      >>I'm working with mozilla, building a little XUL app.
      >>I have a datasource, and want to display a message
      >>once it is loaded (datasource.loa ded is true).[/color]
      >
      >
      > I imagine it'll throw an event at such a time, catch that event, don't
      > test datasource.load ed is true at intervals, in fact if the technology
      > does require you to do this, walk away now, the technology is flawed
      > it should be event driven.[/color]

      The event thing is what I'm looking at right now, but I still wonder how
      to pass arguments to code called by a timeout.

      Thanks for your remark anyway ;-)

      Raph

      [color=blue]
      >
      > Jim.[/color]

      Comment

      • Richard Cornford

        #4
        Re: setTimeout and passing argument

        "Raphael Bauduin" <raphael.baudui n@be.easynet.ne t> wrote in message
        news:3FA912F9.4 020809@be.easyn et.net...
        <snip>[color=blue]
        >The event thing is what I'm looking at right now, but I still
        >wonder how to pass arguments to code called by a timeout.[/color]

        Some setTimeout implementations , probably including Mozilla's (as
        Netscape 4 implemented it) will, when passed a function reference as
        their first argument, accept arguments 3 to n as additional parameters
        and pass these parameters on to the function referenced in the first
        argument when it is called.

        Richard.


        Comment

        • Rich Persaud

          #5
          Re: setTimeout and passing argument

          Raphael Bauduin <raphael.baudui n@be.easynet.ne t> wrote in message news:<3fa90f6a$ 0$1109$6c56d894 @feed0.news.be. easynet.net>...[color=blue]
          > Hi,
          >
          > I'm working with mozilla, building a little XUL app.
          > I have a datasource, and want to display a message
          > once it is loaded (datasource.loa ded is true).
          >
          > So, I thought to use timouts, but as the code to execute is
          > passed as a string, I cannot pass local variable to this code.
          >
          > Anyone has a suggestion?[/color]

          There are more than a few caveats to using setTimeout. Some reading
          material:





          http://jsindex.com (search for 'multi-threading')

          In general, you can create an anonymous function (closure) without
          arguments that retains access to a local variable (like datasource)
          from the enclosing lexical scope. The anonymous function can pass the
          variable as a parameter to the function of your choice.

          Note that Konqueror has (had?) a problem with anonymous functions and
          setTimeout. Workarounds:





          --
          Rich Persaud | weblog > http://dotPeople.com

          Comment

          Working...