So, fun stuff; this doesn’t mean that I’m completely in love with the language, however. It has a few flat-out bugs; the worst is that, if you’re in a method and create an anonymous function, then, inside that function, ‘this’ is bound to the function object instead of the object whose method you are evaluating, which is never the behavior you want. (For that matter, having to type ‘this.’ all the time isn’t too thrilling, either.) And, coming from Ruby, the built-in tools for working with collections are surprisingly weak; I’m glad that I have jQuery.each and jQuery.map to help me, but that should be built into the basic language. (It doesn’t help that the callback that jQuery.each wants has its arguments in the wrong order, either. Hmm, maybe I should be looking into Prototype more?)
This really hit home when I was reworking the game’s keepsakes/scrapbook interface. Both of those pages want to display collections of items; and, on both of those pages, we make a distinction between featured collections (with a green background) and regular collections (with a blue background), leaving us with four different contexts. What I ended up doing was writing a single function that will display all the items in the collection; but outside of the HTML generated by that function I put a div with a class saying whether the collection was regular or featured, and outside of that div I put another div saying whether I was on the keepsakes page or the scrapbook page.
So then I would write simple CSS rules that specified the parts of the layout that were identical in all four contexts: e.g. pictures had the same size no matter where you were. But I’d write two rules for the backdrop: if it was contained within the featured div, the backdrop should be green, while if it’s within the regular div, it should be blue. And there were some bits of the decoration (e.g. buttons beneath the items) that I didn’t want to show at all on the scrapbook page; I’d still generate the HTML for them, but I’d include appropriate CSS selectors to get it not to be displayed on the scrapbook.
I also want to talk about testing, but I’m already over 900 words, it’s getting late, and I’m at a reasonable stopping point. So I’ll come back to that later in the week.
This post has not been revised since publication.