Jon Raasch's notes on Nicholas Zakas's Google Tech Talk "Speed Up Your JavaScript" in which he covers basic performance improvements like local variables for more expensive lookups, avoiding for in loops, casting DOM array-like objects into proper arrays, avoid touching the DOM, use classes to change CSS instead of inline styles.
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.
From Mozilla: An overview of the object-oriented capabilities of JavaScript. This covers OO concepts of classes and objects, instances, abstraction, encapsulation and polymorphism as done in JavaScript with functions and prototypal inheritance.
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.
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.
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.
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.
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.
Erik Arvidsson warns against extending the JavaScript Object with Object.prototype, as it can lead to breakages in third party code when they use the for(key in obj) method of iterating through any class (since they all are subclasses of Object). Instead Erik recommends extending the classes that directly benefit from the extending functions, and treat Object as a final constant. Erik also suggests that hashes and associative arrays should be done in JavaScript using Object, not Arrays.
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.
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.
First in a series of talks from Douglas Crockford about the JavaScript language. These talks cover the JavaScript language, from the history, the language, advanced features, platforms, standards and programming style. Talks about inheritance, using functions to build objects, closures, as well as the basic JavaScript syntax. Also covers code conventions. JavaScript is a language that requires discipline.
Tim explains object orientation in the context of JavaScript, covering concepts like object literal, encapsulation, inheritance using prototype, composition through association and aggregation, polymorphism. Useful read for OO-aware developers to grasp some of the potential of JavaScript.
Dustin Diaz discusses the Object Literal form of JavaScript, pointing out benefits such as better organisation of code in a namespace / wrapper.
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.