Although Christian Heilmann covers what he wished he knew about JavaScript earlier, he actually points out the features JavaScript developers should know: shortcut notations, JSON, native JavaScript functions, event delegation, anonymous functions and the module pattern, allowing configuration, and using good libraries to abstract away browser differences.
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.
Ben Cherry, web developer at Twitter, takes us step by step through the Module Pattern. He introduces the standard features of Anonymous Closures and avoiding global scope, and covers advanced concepts such as augmentation, cloning, inheritance, private state and sub-modules.
Christian Heilmann lays out seven rules to better unobtrusive JavaScript, including not making assumptions about JavaScript, the browser and the document. Work with structured markup. If you are traversing a document, maybe there's a solution that can take advantage of CSS's selector mechanism instead. Work with browsers and users. Better understanding of events, and playing nice with namespace, scope, and patterns. And of course, think about the next developer, so keep the code maintainable.
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.
Eric Miraglia explains Douglas Crockford's Module pattern, a way of creating encapsulated JavaScript functions that offer private and public methods and properties. It uses an anonymous function that returns an object containing our methods, and avoids the big issue of cluttering up the global namespace with global functions. Its based on the Singleton pattern.
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.