JSON and the Ajaxnauts
September 5, 2008
Closures particularly are one of its most awesomely powerful features. Once properly understood they tend to roll off the keyboard almost by accident. It makes you wonder how you ever wrote software which doesn’t have them.
Much like my comments about C# thread syntax being easy to use and abuse without realising it, closures are easy to create, but have potentially harmful consequences for the unwary, particularly in IE. To avoid accidentally stepping on a closure landmine it is necessary to understand their mechanism. This depends largely on the role of scope chains in identifier resolution and so on the resolution of property names on objects.
Laurens van den Oever’s solution to stop you wetting yourself when programming for IE is a good one. Incidentally, I needed a good XML to JSON converter and fairly randomly chose Thomas Frank’s to get me going. I intended to revisit this and write my own, but it’s been so good I shan’t bother – it’s been flawless.