(in parens)

JavaScript Module Pattern

javascript, module, patterns

My co-developers at my previous job were not terribly JavaScript-inclined and I found myself describing a lot of the information below to them any time they looked at JavaScript code with me. I figured I would write it all down as reference.

Not that this is original. YUI talked about it back in 2007. Ben Cherry goes into much greater detail. Jonathan Snook is not a big fan. On and on. I’m adding my two cents because I think it is important to first mention the aspects of JavaScript that make the pattern possible.

The module pattern is extremely useful for namespacing your site’s functionality to help prevent your code from overwriting others’ code (and vice versa). Instead of putting your functionality on the global object where it can easily clobber or be clobbered by other globals, you tuck it away in an extensible module. And if necessary, you can have modules within modules within modules.

But first, a few key JavaScript concepts that enable and naturally lead to the module pattern.

Continued →

Embedding GitHub Gists in Tumblr Posts

gist, github, javascript, jquery, tumblr

(Update; Aug 9th, 2011) This post was originally on my Tumblr blog. I have since migrated to Octopress.

Tumblr’s utter lack of Gist support was pretty much a show-stopper for me, which is why this is my first post. In trying to figure out how to hack it myself, I ran across Jarred Grippe’s post describing how he hacked it. I refactored his solution a bit to add some error checking and a couple of features.

Continued →