Wonderful closures, evil closures!
Monday, April 17th, 2006
One of the things that makes JavaScript (and ActionScript, by association) a wonderful language to program in is it’s support for closures and higher order functions. It’s a powerful feature, and it can greatly simplify all the asynchronous programming that you do in web applications. It also makes it possible to do advanced but useful abstractions of things like iteration and transformations of datastructures.
However, there is a downside to this, and that is what the second half of the title refers to. It’s very easy to fall into a hidden trap: closures are a source for hidden memory leaks.