Klaus Komenda takes us through the history of development patterns of JavaScript demonstrating the pros and cons. Taking a typical JavaScript feature he starts with the old-school global functions method and iterates through a Singleton, Module Pattern, Revealing Module Pattern, Custom Objects and Lazy Function Definitions bringing the same feature up-to-date.
Tim describes another two different approaches to using the Module Pattern (a way of creating Singletons). The first example takes advantage of the natural indentation to clearly see which methods are private and which are public. The second is a curried function, a function that returns another function.
Christian Heilmann offers another incremental improvement to the Module Pattern, and calls it the Revealing Module Pattern. This defines an anonymous object that contains a list of methods and properties that are publicly available. Christian notes that this method also allows you to set up a public property that's privately generated by a method. Christian's improvement makes it quickly clear which properties and methods are public.
Christian Heilmann compares the Object Literal to Douglas Crockford's Module pattern and finds that the Module pattern fixes a major problem of the object literal - the difficult choice of using this or fully qualified references to functions in the same block. Christian also covers the improvements in the Module Pattern, like the decluttering of the return block, which makes the resulting a little easier to work with.
Klaus Komenda discusses a number of ways of encapsulating JavaScript functions into objects and namespaces, and shows how to use each pattern. He covers Singletons, Douglas Crockford's Module Pattern and Custom Objects, building the same functionality with each technique.