Since closures are so great, I should use them whenever possible, right?
A colleague of mine asked me this question this week and I thought that it would be a nice topic for a post. Don’t worry, I’ll be really quick about it!
Instead of saying no, I told him: it depends. “Depends on what?”, you ask. Well, one of the problem with closures is that it slows down your code. It’s relatively easy to understand why: closures also change the scope chain and that means more work for interpreter.
Btw, don’t just start removing closures if the app’s performance doesn’t match your expectations. Before doing that, you need to measure things (if you’re using lots of closures,you might start by measuring the time that operations which involve those closures take). Without that info,you’re not really sure on why something is taking lots of time.