So, “closures”, right? That’s a fun one that tends to cause confusion all around.
It’s pretty much a given that at some point in your life you’ve been walking down the street and overheard two shady guys on a corner whisper about how mighty a concept closures are — and chances are you then went home, tried to look up those mysterious “closures”, and didn’t seem to get what all the fuss was about. After all, they are just doing what any rational being would expect to be done in some way or other anyway, right?
True, closures are so intuitive that it can be hard to grasp why they are even a thing — but once you’ve seen how to not only rely on those faithful little bastards to do the job someone has to do so the whole building that is Javascript won’t come crashing down, but how to intentionally send them into battle in order to accomplish a bunch of really cool things, you’ll be one of those shady whispery types yourself in no time.
‘Nuff said. Here’s what’s gonna happen:
First, I will ease you into the basics, in case you time travelled here from 1974 and have no idea what I’m talking about. There will be a few examples of the stuff you already knew anyway — maybe without even suspecting that closures are involved — and a bit of narrative going on. This is the part where you can lean back and enjoy yourself.
Second, I will explain the situations in which you can greatly benefit from knowing what closures actually do, and show a few examples of closures that don’t “just happen” but are used intentionally to make your life easier.
Third, The Real Life. Not just code snippets, but full commented example pages, with both the code and a live iframe to see the code at work.