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


Groups > comp.lang.javascript > #16307

Re: Quotes are trouble

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!news.albasani.net!.POSTED!not-for-mail
From Stefan Weiss <krewecherl@gmail.com>
Newsgroups comp.lang.javascript
Subject Re: Quotes are trouble
Date Tue, 02 Oct 2012 06:56:38 +0200
Organization albasani.net
Lines 59
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>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-Trace news.albasani.net LLImM+7TkMa5vb19O3dSSdCNSOxqXUDbdoZyHOjceViYe9JWcnFXB6e/3hpk8VHdTxI6PPDn5+uAYfC9dL1m1WsopKhr8T60PqTMbUgeWTm1U7Y3zeJBVi0IKJJq4Ggh
NNTP-Posting-Date Tue, 2 Oct 2012 04:56:39 +0000 (UTC)
Injection-Info news.albasani.net; logging-data="ax854i/r/64fTSADwZKHjYv/1az0UOlBOipufcqxMjhMQcviLA54dvspv+CpvuaCWAmm0MLok0DAEURDoZMXXZaE9/MZORlsCTZETMHVmgXWxqhRgo5rLaprpImuAga0"; mail-complaints-to="abuse@albasani.net"
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120827 Thunderbird/15.0
In-Reply-To <7561a517-388d-4e1d-b2cb-a10bb9da6dc8@o7g2000yqb.googlegroups.com>
Cancel-Lock sha1:sKRdbfxQvtw9dm7YVcwuzwdozXY=
Xref csiph.com comp.lang.javascript:16307

Show key headers only | 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