Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #16307

Re: Quotes are trouble

From Stefan Weiss <krewecherl@gmail.com>
Newsgroups comp.lang.javascript
Subject Re: Quotes are trouble
Date 2012-10-02 06:56 +0200
Organization albasani.net
Message-ID <k4ds67$nod$1@news.albasani.net> (permalink)
References <c94def8d-8e83-4b79-a971-f6be4acb5f84@r7g2000yqa.googlegroups.com> <k4dc2g$3g8$1@news.albasani.net> <7561a517-388d-4e1d-b2cb-a10bb9da6dc8@o7g2000yqb.googlegroups.com>

Show all headers | View raw


On 2012-10-02 02:38, justaguy wrote:
> On Oct 1, 8:21 pm, Stefan Weiss <krewech...@gmail.com> wrote:
>> > err msg:
>> > missing quotes around argument?
>>
>> What kind of an error message is that?
>> You should at least get a line number.

> error line:
> setTimeout(popMain(imgs[i]),1000);

Next time, please include the full error message, so we know what to
focus on. And incidentally, it should tell you, too, where the problem
is (i.e., the setTimeout call).

> But I set up an alert right under popMain function for the parameter
> of img
> alert(img); // and just in case img is special, I renamed it to imag
> to no avail neither
> and it passes its value correctly.

That's because popMain is not the problem, like the error message and I
already told you. The problem the way you call setTimeout. I also
included a link to a page which explains exactly how it works. You
should have read it :(
It states right on the top of the page that the first argument must be a
function reference or a string.

What you're doing instead is this:

  setTimeout(popMain(imgs[i]),1000)

This calls popMain(imgs[i]) right away, without any delay. The popMain
function does its thing and returns nothing (undefined).
Now the execution is at this point:

  setTimeout(undefined, 1000)

And that's where you get the error: "useless setTimeout call (missing
quotes around argument?)", because undefined is not a valid argument for
setTimeout.

Now if you add quotes around the argument -

  setTimeout("popMain(imgs[i])", 1000)

- then the setTimeout call succeeds, but a second later you'll get a
ReferenceError because i is not defined. What you should do instead is

1) read the docs if somebody points you to the relevant page

2) use: setTimeout("popMain(imgs[" + i + "])", 1000)


- stefan


PS: the next surprise will come when your script, now "working", will
only display kn6.png after the timeout. Why?

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Quotes are trouble justaguy <lichunshen84@gmail.com> - 2012-10-01 14:36 -0700
  Re: Quotes are trouble Andrew Poulos <ap_prog@hotmail.com> - 2012-10-02 09:24 +1000
    Re: Quotes are trouble justaguy <lichunshen84@gmail.com> - 2012-10-01 17:01 -0700
  Re: Quotes are trouble Stefan Weiss <krewecherl@gmail.com> - 2012-10-02 02:21 +0200
    Re: Quotes are trouble justaguy <lichunshen84@gmail.com> - 2012-10-01 17:38 -0700
      Re: Quotes are trouble Stefan Weiss <krewecherl@gmail.com> - 2012-10-02 06:56 +0200
        Re: Quotes are trouble justaguy <lichunshen84@gmail.com> - 2012-10-03 21:33 -0700
          Re: Quotes are trouble "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-04 07:58 +0000
  Re: Quotes are trouble Denis McMahon <denismfmcmahon@gmail.com> - 2012-10-02 03:21 +0000
  Re: Quotes are trouble Norman Peelman <npeelmandog@cfl.rr.com> - 2012-10-02 01:57 -0400
  Re: Quotes are trouble Matt McDonald <matt@fortybelow.ca> - 2012-10-02 12:43 -0400
  Re: Quotes are trouble Dr J R Stockton <reply1240@merlyn.demon.co.uk.invalid> - 2012-10-03 19:27 +0100
    Re: Quotes are trouble justaguy <lichunshen84@gmail.com> - 2012-10-03 21:34 -0700

csiph-web