Based on Simon Willison's original 2005 eTech talk, Simon expands this into a full article covering the expressive functionality of JavaScript. He covers the basics of JavaScript: literals, variables, functions, scope, control flow, objects, classes, inner functions and closures. Everything a developer needs to know before diving into more advanced JavaScript.
John Resig explains JavaScript timers. Because of JavaScript's single-thread nature it is easy to write blocking code that makes pages unresponsive. Timers allow us a mechanism for yielding control back to the browser, queueing the code up to run a little later. John goes into depth on this particular topic.
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.
Angus Croll takes the reader step-by-step through some basic JavaScript code explaining what 'this' is in each step and why. He explains how 'this' depends on the execution context, and how it is manipulated by how JavaScript functions are called (or applied or bound with bind), and how Constructors create a new context.
Tim Caswell describes the JavaScript variable 'this', which is about current scope and current context. The only way to create scope in JavaScript is through function definitions, and in most cases the context is the receiver of the message (the object before the dot in the method call). He also talks about approaches to controlling what this references with call, apply and bind.
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.
Cory Hudson sees callbacks as benefiting from currying JavaScript functions, and defines currying as turning a function with two arguments into a function with one argument that returns a function of one argument. He starts off with two functions and shows how to combine them into one curried function, and also builds a generic version. He shows a good usage of a curried function in an array map()
function, which is similar to Prototype's bind()
.
Jonathan Snook demonstrates when JavaScript passes by reference or passes by value. Essentially, primitive types are passed by value, objects are passed by reference. Passing functions however, makes things look like a pass by value if the 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.
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.
The Yahoo! Web Developer Network provides a one page overview of JSON, giving a quick tutorial on JSON, how to get Yahoo! Web services to emit JSON, offering an output of a JSON object literal as well as using a callback function method. Yahoo! also describes how their web services typically translate their XML structures into JSON.
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.
Douglas Crockford's presentation on Advanced JavaScript. He covers topics such as inheritance, modules, debugging, efficiency and JSON.
Douglas Crockford's JavaScript code conventions. Covers indentation, line length, comments, variable and function declarations, minification, statements and labels, whitespace, scope and eval.