Observer

A way of notify changes to a number of objects.

The Observer patterns is ubiquitous in jQuery: anywhere jQuery deals with events.



Overview


The Observer pattern allows functions to register themselves for notification when a particular event occurs. These functions are called event handlers. This pattern is at the core of all event-driven programming, including JavaScript. Not surprisingly then, the Observer pattern is a big part of jQuery: it has many dozens of objects, properties, and methods that are involved with events.

The newer on and off methods in jQuery are used to make it easy to attach and detach handlers to any event you specify. Here are some examples.

Attach a handler to the click event:

$("#menu").on("click", function (e) {
    alert("menu was clicked");
});

Remove all click handlers:

$("#menu").off("click");    

The trigger method fires an event programmatically. All registered event handlers will execute.

$("#menu").trigger("click"); 



  Iterator
Proxy