A practical walkthrough of using map/reduce with MongoDB to aggregate statistics for generating a report.
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.
A simplified explanation of closures by Morris Johns: A closure is the local variables for a function - kept alive after the function has returned.
A clever hands-on interactive mini-course by Nathan Whitehead that guides you through bite-sized chunks from variables, to functions, to return values, to functions as first-class objects and right into closures and finally continuations. The hands-on exercises are JS Linted and unit-tested which gives you ample space to try out your new-found knowledge.
Remy Sharp dissects a piece of jQuery code pointing out the red flags. Each flag is taken in turn, explained and shown how to correct. Takes into account context and the flexibility of jQuery
Fellow co-worker Lawrence Carvalho discusses the Undo functionality, and as web based applications start to replace desktop ones, this crucial bit of functionality will become expected by application users. Lawrence talks about the Memento design pattern and guides us through designing objects that can undo their changes. He builds an undoable text widget.
map() function, which is similar to Prototype's
this keyword is being used in the code. Snook offers workarounds to this by passing objects so that the context is correct, or using the
call() function to ensure the context is correct.
Dan Webb describes curried functions as a way of creating reusable callback functions for event handlers or Ajax requests, or anything that takes a function as an argument. By using closures, curried functions have a simple way of persisting data between calls. He also offers an elegant way of running a lots of methods on objects, with a simple map function written as a curried function.
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.
Simon Willison blogs about how JQuery won him over. From its faddish start based around CSS selectors (getElementsBySelector), and method chaining, Simon now sees the library in a new light. Simon shows how jQuery supports modern development best practice such as namespaces, giving a quick nod to the richness of jQuery selectors (DOM, CSS and XPath). JQuery's event handling looks natural and offers an event when the dom is ready. It exposes custom events for non-trivial Ajax requests. Simon's so convinced about jQuery that he's willing to overlook his rule that developers should know how a library works before using it.
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.
Tim Huegdon and Mark Aidan Thomas create an elegant wrapper to the YUI Connection Manager that manages repeating Ajax JSON requests. Tim describes the use of Custom Events, and the use of the Observer design pattern, dissects the code and offers a tidy demonstration of the working code. This simplifies JSON requests into declaring a simple function to process the returned JSON object, and a single line to fire off the request (within a setInterval if required)
An online copy of O'Reilly's 2002 book Creating Applications with Mozilla. It focused on pre-1.0 versions of Mozilla, so details about the application structure has changed, but the XUL elements are relatively stable.
Stuart Colville investigates the differences between form.getAttribute('action') and form.action, also the cross-browser differences, when the action is a relative URL. One way returns a relative URL, and the other returns a fully qualified URL.
Dean Edwards takes Mozilla's newly introduced forEach method, and implements it for non-Mozilla browsers, for enumerating over objects and arrays.
Instead of creating a new XmlHttpRequest object for every request, this post provides code to pool these objects together and reuse them. This saves a great deal of processing times, particularly in IE.
Three top features of jQuery: the multitude of selectors, manipulating attributes, and tacking Ajax/JSON requests. Choses jQuery over Prototype
Christian Heilmann describes an approach to building complex web application by basing them around events, particularly around YUI's CustomEvent class.
Christian Heilmann does a tree menu without using loops. It demonstrates the flexibility and power of Event delegation - catching events at a higher level in the document. It drastically cuts down on the number of events you need to add to a document. One event handler per menu, rather than one per link in the menu.
Michael Mahemoff runs into a problem with Protypes $$ function when looking for class names. Its taking over 90 seconds when more than 100 matches are returned. The advice is: Avoid $$(".classname") on large DOMs.
Christian Heilmann demonstrates delegating events, and compares it to the main alternative of assigning event handlers to each individual node. Its a technique that's important for writing applications that can scale.
Douglas Crockford discusses how to create private members and methods, and using privileged methods to bridge the gap between public and private. It also contains the simplest and most understandable definition of closures I've ever seen.
An explanation of scope in terms of an execution context and scope chain. Also describes how we can alter the this reference using apply and call.
An overview of object literals and object oriented programming, referencing attributes and functions, prototype objects, creating singletons.
LowPro is a scripting extension to Prototype written by Dan Webb to make unobtrusive DOM Scripting much easier. Included are an onReady event, adding behaviour using CSS selectors, fixing the this reference to always refer to the element within events, and a mechanism for triggering events.
Dustin Diaz makes the case for using YUI Event Utility over the currently popular addEvent. The benefits Dustin points out include automatic scope correction, automatic browser abstraction.
As well as supporting CSS based selectors, jQuery also supports XPath expressions. This page lists a plethora of code snippets demonstrating jQuery's XPath matching capabilities.
Covers all the methods available on the jQuery library, along with inline code examples. Interestingly, the same documentation is also available as XML and JSON.
A useful overview / introduction of the jQuery library, covering using selectors and XPath expressions to target specific elements in a document, simple Ajax requests, the basic animations available, restructuring a document, creating jQuery plugins.
A collection of gotchas and guidance in Greasemonkey scripting. Positioned as an addition to Mark Pilgrim's dive into Greasemonkey
Mark Pilgrim's essential online book about developing Greasemonkey scripts. Excellent starting point for Greasemonkey developers. Covers everything from setting up a Greasemonkey scripts to common DOM coding idioms, as well as a brief rundown of XPath, and case studies of Greasemonkey scripts.
Mark Pilgrim dissects the security issues of the 0.3 Greasemonkey, and describes how the new architecture of Greasemonkey works, pointing out pitfalls and how to address them.
Speeding up object detection by doing the detection once. Dean Edwards demonstrates a quick improvement using the ubiquitous addEvent function.
Dean Edwards counters Dojo's Alex Russell's hideous hacks with two standards friendly approaches. Looking at the The DOM Content loaded problem and the sluggishness of walking a DOM Tree, Dean talks about speed improvements, including the use of XPaths.
Dean Edwards presents his improvement to Scott Andrews' famous
addEvent() functions. Solving the cross-browser
this reference differences, and passing
event objects correctly.
Dean Edwards gets to grips with the
window.onload problem - where it only gets fired once the document and its associated styles and images are loading. The ideal solution is one that that detects when the document is available as a DOM.
A lightweight library designed to elegantly dealing with common, repetitive tasks. Great as a small library to handle getting various nodes in a document, adding events, and rendering simple effects.