JavaScript–The Revealing Module Pattern

JavaScript–The Revealing Module Pattern

Working as a consultant, I get to see a lot of code written by different people. One of the things that consistently surprises me is how much JavaScript I still see written inside html pages. Haven’t we reached a level of maturity on the web where we as developers understand that there are essentially 3 distinct parts to a web page? The structure, the style and the behavior. What’s funny is that these same developers who are polluting their markup with script would never think to use inline styles in their pages. Somehow inline styles fall into the unacceptable camp but as for script…..meh.

Perhaps one of the reasons I continue to see this unfortunate phenomenon is that these devs don’t know how to move their code out of  the page and set it up in such a way as to not pollute the global space? That’s just speculation of course but for the purposes of this post, lets assume that’s the case. Let us further assume that if these folks did embark on a journey to get JavaScript out of their markup, all they would do is move their list of functions and event handlers out of the page and into an external .js file. That would be bad. All we’ve done is move the problem from one place to another.

There must be a better way . Fear not, there is a better way. A few of them in fact but the one I’m going to focus on here is a little pattern called the Revealing Module Pattern.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get Adobe Flash player