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


Groups > comp.lang.javascript > #32525

Re: setInterval

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: setInterval
Date 2017-02-07 04:36 +0100
Organization PointedEars Software (PES)
Message-ID <2203914.Sgy9Pd6rRy@PointedEars.de> (permalink)
References (3 earlier) <daeac930-8fcd-48c9-b280-75144f751b0e@googlegroups.com> <8e741582-e2a8-4713-b49d-6bd5a50a8317@googlegroups.com> <fb53f70d-b831-4f1e-b290-eaad38124c77@googlegroups.com> <ac8011b3-9496-4559-a42b-c656798bfc44@googlegroups.com> <87h947e7f5.fsf@bsb.me.uk>

Show all headers | View raw


Ben Bacarisse wrote:

> jonas.thornvall@gmail.com writes:
> <snip>
>>> > > > > >   var interval_1 = setInterval("COUNTDOWN();",1000);
>>> […]
>>> > > > > >  if(mycount<1) clearInterval(interval_1);
>>> […]
>> Well it work but
> 
> I'm surprised that works.  The first argument of setInterval should be a
> function not a string.

The string argument is historic because there were no function expressions 
when this method was introduced in Netscape 2.0, JavaScript 1.0 (since 
JavaScript 1.4 it is no longer part of the programming language, but of the 
language-independent Window API).

And yes, it is better to use a Function instance reference, for two reasons:

  1. it is safer: nobody can replace the function to be called and have it
     executed instead;

  2. it is more efficient: this is a kind of “hidden eval()” (IIRC that was 
     the term used)

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

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


Thread

setInterval jonas.thornvall@gmail.com - 2017-02-05 23:26 -0800
  Re: setInterval jonas.thornvall@gmail.com - 2017-02-05 23:30 -0800
    Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 00:17 -0800
      Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 00:24 -0800
        Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 00:36 -0800
          Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 01:10 -0800
            Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 01:20 -0800
              Re: setInterval Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-02-06 14:10 +0000
                Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 11:25 -0800
                Re: setInterval Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-02-06 21:12 +0000
                Re: setInterval Silvio <silvio@internet.com> - 2017-02-06 22:15 +0100
                Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 14:17 -0800
                Re: setInterval "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-06 23:50 +0100
                Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 20:57 -0800
                Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 21:15 -0800
                Re: setInterval "Julio P. Di Egidio" <julio@diegidio.name> - 2017-02-07 06:22 +0100
                Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 22:09 -0800
                Re: setInterval Julio Di Egidio <julio@diegidio.name> - 2017-02-06 22:27 -0800
                Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 22:45 -0800
                Re: setInterval Jake Jarvis <pig_in_shoes@yahoo.com> - 2017-02-07 11:13 +0100
                Re: setInterval Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-02-07 17:23 +0100
                Re: setInterval Julio Di Egidio <julio@diegidio.name> - 2017-02-07 11:54 -0800
                Re: setInterval Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-02-07 21:54 +0100
                Re: setInterval Julio Di Egidio <julio@diegidio.name> - 2017-02-07 13:50 -0800
                Re: setInterval Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-02-07 23:19 +0100
                Re: setInterval Julio Di Egidio <julio@diegidio.name> - 2017-02-07 15:33 -0800
                Re: setInterval Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-02-09 00:23 +0100
                Re: setInterval "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-07 11:33 +0100
                Re: setInterval "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-06 23:28 +0100
                Re: setInterval "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-06 23:26 +0100
                Re: setInterval "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-06 23:24 +0100
                Re: setInterval Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-02-07 04:36 +0100
            Re: setInterval Silvio <silvio@internet.com> - 2017-02-06 16:13 +0100
              Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 12:10 -0800
                Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 12:27 -0800
                Re: setInterval "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-06 23:16 +0100
                Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 14:28 -0800
                Re: setInterval "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-06 23:45 +0100
                Re: setInterval Tim Streater <timstreater@greenbee.net> - 2017-02-06 21:25 +0000
                Re: setInterval "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-06 23:19 +0100
  Re: setInterval JJ <jj4public@vfemail.net> - 2017-02-06 20:07 +0700
    Re: setInterval "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-06 16:00 +0100
      Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 11:06 -0800
        Re: setInterval "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-06 23:08 +0100
          Re: setInterval jonas.thornvall@gmail.com - 2017-02-06 14:26 -0800
            Re: setInterval "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-02-06 23:41 +0100

csiph-web