      1 pockets.Observable = function() {
      2   this._observers = [];
      3 };
      4
      5 pockets.Observable.prototype.addObserver = function(assistant) {
      6   /* push an anonymous function instead of the object itself so
      7        that nobody tries to iterate through the observers' properties,
      8        which can sometimes result in circular references */
      9   this._observers.push(function () {
     10     return assistant;
     11   });
     12 };
     13
     14 pockets.Observable.prototype.notifyObservers = function() {
     15   this._observers.each(function(assistantReferenceFunction) {
     16     var assistant = assistantReferenceFunction();
     17     assistant.controller.modelChanged(this, assistant);
     18   }.bind(this));
     19 };
     20
     21
     22 pockets.Observables = {};
     23
     24 pockets.Observables.makeObservable = function(model) {
     25   if (!model._observers) {
     26     model._observers = [];
     27   }
     28
     29   model.addObserver = pockets.Observable.prototype.addObserver;
     30   model.notifyObservers = pockets.Observable.prototype.notifyObservers;
     31 };
     32
     33 /** @deprecated Use pockets.Observables instead */
     34 var Observables = pockets.Observables;
     35