In .NET you can add multiple handlers to an event which an object declares as an event.
What is the recommended way for handling this in JavaScript for non-DOM objects?
i.e. I have an object:
var ProblemDomainObj = {} ;
ProblemDomainObj.Changed = function() {} ;
ProblemDomainObj.Data = { somedata : "initialized" } ;
ProblemDomainObj.Operate = function (newdata) {
if (newdata != somedata && ProblemDomainObj.IsValid(newdata)) {
somedata = newdata;
ProblemDomainObj.Changed();
}
} ;
Now other objects may want to register to know that the data has changed and each want to do something like this:
ProblemDomainObj.Changed += function() {
/* Do stuff to reflect the object model changes */
} ;
Where each gets to register their handler without overwriting the other.
Then some object will call ProblemDomainObj.Operate(foo); and all those who have subscribed will get notified.
I have found the documentation in jQuery for http://api.jquery.com/on/ but it seems to relate to DOM events like onclick. None of this would necessarily be related to the DOM.
jQuery works great on regular objects as well: http://jsfiddle.net/gMNkg/.