Creating a Utilities Object

The samples that we build throughout the rest of this book will rely heavily on specific DOM-related methods. These methods will simplify common JavaScript functions, create any HTML element that we need, and be reused to avoid the duplication of common code throughout our applications.

Before we create any methods, we must first instantiate the Utilities object as follows:

Utilities = {};

This object is based on the Singleton pattern, which we will discuss in Chapter 14, “Singleton Pattern.” Creating methods in this object is simple: First use the name of the object, followed by the name of the method. Take a look at the following example:

Utilities.createElement = function() {}

The methods that currently exist in ...

Get Ajax for Web Application Developers now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.