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 stackoverflow community article explaining closures in plain simple English does a great job. Succinctly: a closure is created when inner function that gets returned. The inner function can still see the variables and methods defined in the outer function.
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.
Angus Croll covers the new 'use strict' operator introduces in EcmaScript 5th edition and how to get started using it. He offers a set of unit test to see how well supported strict mode is in your browser.
Douglas Crockford explains the new strict mode introduced in the 5th edition of ECMAScript. It is an opt-in mode that repairs or removes some of the language's most problematic features such as: function scoping, implied global variables and global leakage, read-only variable failures, octal defaults and function arguments.
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
PPK describes the this keyword as a reference to the owner of the function we are executing, or the object that a function is a method of. He then compares how attaching a function to an event in two different ways affects what the this keyword references.
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.
Jim Ley covers the intricacies of type conversion, implicit and explicit. He covers type conversion into boolean, string, number, undefined, null; and parsing into floats and integers. This is backed up by conversion tables for quick reference. There's also a useful section on regular expressions for form field validation.
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.
David Dorward compares dot notation and square bracket notation, where square bracket notation can be used where dot notation can't. Recommends using dot notation, because its easier to read, and square bracket notation when it can't be done with dot notation.
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.
Exploring the features of Firebug, with code examples covering using the console, timing code, stack traces, debugging and breakpoints, profiling, tracing HTTP requests. An excellent overview of Firebug's functionality
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 evolt article that covers using Regular Expressions, including the difference between static and dynamic regular expressions (compiled at compile time or runtime respectively). Good selection of tables such as regex modifiers, patterns and escaping, look ahead, backreferences. Includes a short section on usage. A neat short cheatsheet for starting to use regular expressions.
As web pages become more and more like applications, code performance becomes more and more important. This article looks at a number of performance issues to avoid, in EcmaScript, DOM and AJAX requests. Covers eval, the with keyword, try/catch in performance-critical code, global variables, implicit object conversion, string concatenation, primitive operations over function calls, repainting and reflowing documents, modifying elements, using XPath.
Jack Slocum presents a simple recipe to avoid memory leaks, including setting onreadystatechange to null on completion of an XMLHttpRequest, clean up DOM Event handlers on unload, never put non-primitives into a DOM node.
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.
Christian Heilmann describes an approach to building complex web application by basing them around events, particularly around YUI's CustomEvent class.
Guides, notes, overviews, documentation for the Prototype library. Pathfinder compiles a list of useful resources for this library.
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.
Ryan Campbell shows how to get the Prototype library up and running, and introduces and documents Protoype's $() function. Form helper functions, getElementsByClassName functions, Element helper functions, Ajax support, timer functions are all covered.
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.
Svend Tofte puts together a detailed guide to setting up and using the Venkman debugger. From basic debugging to watchlists and call stacks, breakpoints, and more advanced techniques like meta comments and profiling. It also contains a list of other useful Venkman resources.
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.
PPK describes the three main data formats for requesting data from the server, weighing up the advantages and disadvantages. In the ensuing discussion the general feeling is that JSON is the most popular and simplest method.
A collection of gotchas and guidance in Greasemonkey scripting. Positioned as an addition to Mark Pilgrim's dive into Greasemonkey
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.