[sf-perl] OffTopic: Any JavaScript programmers here?

Kevin Frost biztos at mac.com
Fri Jul 4 14:21:55 PDT 2008


I think you just want to use a global variable or, if you're doing  
things right and using namespaces, a property in your namespace object.

VICKI.ListCache.set_list( someIdString, myLocalList );

VICKI.ListCache.get_list( someIdString );

...where you've previously set up container properties within  
VICKI.ListCache or, even better, in its prototype.

However, it sounds like the immediate solution is to just use a global  
variable.  Setting up proper objects in your namespace is a Very Good  
Practice (and not doing it will hurt you later, guaranteed) but that  
may be more of an advanced topic than you're ready for right now.

If you want it to survive reloads, you actually *must* stash the data  
somewhere outside of memory, and you have three options for that, in  
descending order of complexity: a cookie, the server, and the URL.

Also, if you're not doing so already, look into using a good toolkit.   
jQuery is getting a lot of traction right now; Dojo and YUI are also  
good; mootools is nice and light; MochiKit is really powerful but very  
programmer-oriented and semi-abandoned by its owner; and there are  
many others.

cheers

-- f.


On Jul 4, 2008, at 2:06 PM, Vicki Brown wrote:

> I know this is a Perl list but many Perl programmers know more than  
> one
> language.
>
> I have a JS question and don't know where to find the answer. I want  
> to
> implement an "Undo" for a dynamic change to a page.
>
> Please respond off list if you can help me.
>
> The problem
> Basically, I'm sorting a list with JS. It's a bullet list, converted  
> into
> an array for sorting and then back to replace the original bullet  
> list.
>
> I want to save the original list object or array or whatever is most
> convenient before the first sort so I can put up a "put it back"  
> button or
> link. I prefer not to get involved with Cookies.
>
> Workaround: I know I can just reload the page but that changes  
> position
> and  also takes more time.
>
> Does anyone know of a convenient way to stash a copy of the array,  
> or the
> list object itself, grabbed originally with
>      var theList = document.getElementById(ListHandle);
> into a variable that will still be there when I come back the next  
> call
> to the JS?
> -- 
> - Vicki
>
>     ZZZ
>  zzZ                   San Francisco Bay Area, CA
> z  |\     _,,,---,,_   Books, Cats, Tech
> zz /,`.-'`'    -.  ;-;;,_  http://cfcl.com/vlb
>  |,4-  ) )-,_. ,\ ( `'-'  http://cfcl.com/vlb/weblog
> '---''(_/--'  `-'\_)      http://twitter.com/vlb
> _______________________________________________
> SanFrancisco-pm mailing list
> SanFrancisco-pm at pm.org
> http://mail.pm.org/mailman/listinfo/sanfrancisco-pm



More information about the SanFrancisco-pm mailing list