All the recent frenzy over AJAX has gotten me looking at a lot of really great javascript. Anytime I see good code, I get inspired to learn something from it and push my abilities a bit. So I've been playing around with something that has long been an issue for me. You see, in a lot of my applications I end up dynamically generating at least certain parts of the page via javascript. I find it's often easier to return data from the server in a javascript datastructure and then rely on the javascript to build up whatever form elements I need so that the user can modify it. But one thing that's been hard to deal with is how to get this data from the form back into the original datastructure. Sure, it's possible to manually add onclick/onchange/etc. handlers by concatenating a lot of strings, but it's just ugly and not very reusable. For instance, in a recent application, I found myself doing this:

td.innerHTML = 
  '';

Yuck! But reading through all this AJAX code and the related libraries that it's brought to attention has led me to investigate javascript support for closures. Closures, for those of you who don't already know are a way to preserve a state across function calls. This is, they let you carry around a set of variables that seemly would have gone out of scope by the time your function is called. This is a very powerful idea (read more here).