The observer is represented by the constructor that you invoke with var o = new Observer();
and then o
will be an object with a link to a bunch of functions. you add functions to the list through subscribe
. and remove them from the list via unsubscribe
then the whole point of everything is the fire
method, which will cycle through the list of functions, and then call each of the functions one by one. "observer pattern"
seems to be very similar to a singleton pattern
Are you familiar with the watch
method in JavaScript? its method is supported through Firefox, which you can use on any object.
document.myform.myfield.watch('value', function (v) { alert(v); return v; })
then whenever the value of an object changes, the watch
function is called. so basically the concept of the observer pattern is that you want to basically mimic the method of viewing Firefox in a cross browser.
you throw a link to a bunch of functions or objects in the list.then
subscription have Observer.fire
callback method call for each of the observed objects or functions. if the user performs some action, such as a click, then the entire list of functions will be updated through the callback function
Hope this helps.
source share