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