title: My publisher does not return the subscribed function - DIY pub/sub implementation
body: <p>I'm implementing a simple pub/sub in javascript to help me fully understand how this pattern works:</p>
  
  <pre><code>//obj to hold references to all subscribers
  pubSubCache = {};
  
  //subscribe function - push the topic and function in to pubSubCache
  subscribe = function (topic, fn) {
      pubSubCache[topic] = fn;
  };
  
  //publish function
  publish = function (topic, obj) {
      var func;
      console.log(obj);
      console.log(pubSubCache);
      // If topic is found in the cache
      if (pubSubCache.hasOwnProperty(topic)) {
          //Loop over the properties of the pubsub obj - the properties are functions
          //for each of the funcitons subscribed to the topic - call that function and feed it the obj           
          for (func in pubSubCache[topic]) {
              //this console.log returns a long list of functions - overloadsetter,overloadgetter,extend etc
              //I expected to see the 'therapist' function here...
              console.log(func);
              //error occurs here - it should be calling the therapist function
              pubSubCache[topic][func](obj);
          }
      }
  }; 
  
  
  function therapist (data) {
      alert(data.response);
  }
  
  subscribe('patient/unhappy', therapist);
  publish('patient/unhappy',{response:'Let me prescribe you some pills'})
  </code></pre>
  
  <p>​</p>
  
  <p>I'm almost there but seem to have a strange problem in my code. The publisher function searches through the object that holds all the references to the subscribers and successfully finds a match. Then when I try to do a for in loop to get a reference to the function that is subscribed I get back this long list of functions instead of the function I want:</p>
  
  <p>overloadSetter 
  overloadGetter 
  extend 
  implement 
  hide 
  protect 
  $family 
  $constructor</p>
  
  <p>I initially thought these functions were from the prototype of the function but they are not. </p>
  
  <p>Any ideas? Hope this makes sense.</p>