Using the Singleton Object

In the previous section, we learned how to create an object using the Singleton pattern. Now we will discover how to access it from other objects in a web application. The AjaxUpdater object can be used in any other object throughout your web application, all we need to do is import the file.

<script type="text/javascript" src="../javascript/utils/AjaxUpdater.js"></script>

Because the object instantiates itself, it is usable from the moment the file is loaded and can be called directly by name from any object that is loaded into the same page. Using a Singleton object method and property, such as the AjaxUpdater, is extremely easy. The following line of code makes an XHR and sets a callback method, which waits for the ...

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.