View http://doctrina.org/Javascript-Function-Invocation-Patterns.html
As I reflect on that habits I picked up and hopefully left behind along the years, I realize that if I was anything it was inconsistent. I see those traits sneaking in my work even today, especially if I’m excited about something and just want to see it work. I think that might be a curse of many programmers, something we might not grow out of until we really mature our craft. Sometimes when I’m building something out, I haven’t thought it all the way through and therefore can’t have a nice architecture the first time around. Other times I’m building something for the first time and simply cutting my teeth as I learn, so the next time will be even better.
JavaScript is a shining example of this fault of mine. I look back on the stumbling I used to do when first messing with the DOM and realize just how many of these invocation patterns I mixed, matched, copied, and pasted until it worked. this
was a big mystery to me for a long time so I’d try combinations of this
, $(this)
, and seemingly anything in between until my super cool snippet was working like the demo. I wish I had this straightforward explanation to help me better structure my JavaScript a few years ago, but who knows if back then it would have even made sense.