Unregister Observers

The next method is the unregisterObserver method, which is used to remove observers from the collection so that they are no longer notified when an event occurs. Listing 16.4 shows the method as it is used in ErrorManager.

Listing 16.4. Unregistering Observers (ErrorManager.js)
ErrorManager.unregisterObserver = function(_observer)
{
    for(var observer in ErrorManager.observerCollection)
    {
        if(_observer == ErrorManager.observerCollection[observer])
        {
            ErrorManager.observerCollection.splice(observer, 1);
        }
    }
 }

This method receives a codestring as did the registerObserver method. It then uses this string while iterating through the collection by checking to see whether there is a matching codestring in the collection. When and ...

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.