Hi all, I'm trying to implement a somewhat generic way for my controller objects to listen for changes to various properties of my model objects. I'm not a javascript expert, so there is quite possibly a Better Way™ of solving the bigger problem - I'm open to pointers in that direction, if my current approach is not a good idea.
Here's the machinery I currently have in place: MyClass.prototype.observeValueChange = function(observer, property, callback) { if (this.observableChanges == null) this.observableChanges = new Hash(); if (this.observableChanges.get(property) == null) this.observableChanges.set(property, new Hash()); this.observableChanges.get(property).set(observer, callback); } MyClass.prototype.fireValueChanged = function(property) { if (this.observableChanges == null) return; var observerInfo = this.observableChanges.get(property); if (observerInfo == null) return; observerInfo.each(function(info) { info.key.info.value(this)); }); } Here's an example of registering to listen: objectOfMyObservableClass.observeValueChange(this, 'foo', function (destination) { alert("observed change in foo"); }); objectOfMyObservableClass.fireValueChanged("foo"); Tracing through the code, everything appears fine up to the point where I try to call the stored callback. This line: info.key.info.value(this)); info.key and info.value are both valid objects, but nothing happens. Thanks in advance! -- You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.