[Javascript] Question about prototype library, but more to the point about Javascript

Paul Novitski paul at juniperwebcraft.com
Mon Oct 26 17:06:10 CDT 2009


At 10/26/2009 05:39 AM, Terry Riegel wrote:
>function checkIn(l,p){
>   checkIn = new PeriodicalExecuter(
>    function(pe){
>     new Ajax.Request(l,{
>       method: 'GET',
>       parameters: 'ajaxrequest=TRUE',
>       encoding: 'UTF-8',
>       onComplete: function(t){
>        logit('checkin()',t.responseText);
>        if (returnErrorCheck(t.responseText)) {this.stop;}
>        clearImage="undefined";
>       }
>      });
>      return false;
>    },
>    p);
>}
>
>And it starts this thing that happens every p seconds. Fine enough.
>Now At some point in the future I want to stop that thing that is
>firing every p seconds.
>
>How do I reference the local variable checkIn to stop it. I would like
>to do this without making checkIn a global variable as there may be
>more than one checkIn's running.


In the future you'll be able to use getters & setters cross-browser 
to operate on values within an object, but unfortunately they don't 
work in IE as of v8.
http://www.robertnyman.com/javascript/javascript-getters-setters.html

If the necessity of maintaining multiple instances is really your 
only reason for not using global variables, why not simply keep an 
array of checkIns and write a set of functions that maintain it? A 
function that adds a new checkIn locates the first available slot and 
returns a pointer to that array element.

Regards,

Paul
__________________________

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 




More information about the Javascript mailing list