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 the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.