As an added bonus totally unforseen by me, when removing the element that 
the object was initialized in - it seems to remove the object too ...

i.e the Object was created in an ajax callback in an element .. once i 
applied $('div').remove(); to the element that created it then it seems to 
remove it !!!

Bonus :D


----- Original Message ----- 
From: "T.J. Crowder" <[EMAIL PROTECTED]>
To: "Prototype &" <>
Sent: Wednesday, November 19, 2008 12:56 PM
Subject: [Proto-Scripty] Re: Nulling or stopping Dynamic Variables

Hi Alex,

You can do this pretty easily with properties of an object.  The cool
thing about properties of objects in JavaScript (well, *one* of the
cool things) is that you can reference them both literally using
dotted notation and via a string using bracket notation.
Consequently, these snippets are all functionally identical;

1) x = myobject.myproperty;
2) x = myobject['myproperty'];
3) x = myobject[s]; // (assuming 's' is a variable containing the
string "myproperty")
4) x = myobject['my' + s]; // (assuming 's' contains the string

You get the idea.

So somewhere appropriate (if it has to be global, so be it, but if you
can avoid that...), create an object that will contain these:
* * * *
var pebag = {};
* * * *

Then make your references properties on that object:
* * * *
pebag.checkRecord_123423414 = new PeriodicalExecuter(function() {
* * * *

Then when you want to get rid of them:
* * * *
delete pebag['checkRecord_' + s];
* * * *
...where 's' is a variable containing the string '123423414'.

If you prefer not using something like 'pebag', you could use the
window object (and many do), but FWIW I'd recommend using something
specially for the purpose; the namespace of the window object tends to
get crowded, not least because of the Horror of Implicit Globals.[1]


T.J. Crowder
tj / crowder software / com

On Nov 19, 12:12 pm, Jeztah <[EMAIL PROTECTED]> wrote:
> Mornign Guys/Girls
> I am having some trouble nulling out or stopping some dynamic
> variables i have created ...
> I have built a dynamic window system which does alot of things, one is
> checking a database to ensure the most up to date information is in
> input boxes ... Now to check this i create a dynamic variable when the
> contents is loaded via an ajax request...
> [code]
> checkRecord_<?php echo($rand); ?> = new PeriodicalExecuter(function()
> {
> testingRecord('<?php echo($rand); ?>');
> },7);
> [/code]
> in this rand is just a unix epoch on when the page was created and is
> referenced throughout the whole entire page and all its elements ...
> for those that dont know php here is a simpler version of the code
> [code]
> checkRecord_123423414 = new PeriodicalExecuter(function() {
> testingRecord('123423414');
> },7);
> [/code]
> in the DOM there is now a variable called
> "checkRecord_123423414" (please bear in mind this is dynamic so i cant
> just do checkRecord_123423414=null; when i want to null it or stop the
> object as the ending string is allways different dependant on what
> page you are on ...
> Now the problem i get is when closing the windows in the system (which
> are just div containers) i have to stop observing alot of stuff ...
> this is done quite easily with stopObserving();
> But i need to stop the PeriodicalExecutor from continuing once the
> window is closed ...
> i have tried to use "checkRecord_+e.stop();" (`e` is the random string
> passed to it) but it gives me a syntax error
> i have tried to use "checkRecord_+e=null;" but the interpretor does
> not recognise the dynamic variable ..... is there a way i can assign
> the variable to something so it inherits all of the things i need to
> stop in it ..
> Something like (PSUEDO CODE)
> [psuedo code]
> var blah='checkRecord_'+e;
> blah=null;
> [/psuedo code]
> Will this inherit the "new PeriodicalExecutor" stuff in it so i can
> null the object and stop it listening ?
> It allready half works just by closing the window, but if you close it
> while its doing a request (testingRecord();)
> it moans about things being null (as they are removed from the dom
> prior to the object being nulled out !!!
> Sorry if this makes no sense at all !! if anything needs clarifying
> please ask
> Regards
> Alex

You received this message because you are subscribed to the Google Groups 
"Prototype &" group.
To post to this group, send email to
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at

Reply via email to