title: Uncaught TypeError: X has no method 'Y' - but Y *is* declared
body: <p>// Now answered - see line in code</p>
  
  <p>I'm getting thrown an exception because supposedly the method I'm calling isn't declared. But actually it is, so I'm not sure why it's happening</p>
  
  <pre><code>Uncaught TypeError: Object #&lt;Unit&gt; has no method 'onLoopEvent' 
  </code></pre>
  
  <p>And the code is</p>
  
  <pre><code>function Unit () {
       var item = new Item();
       item.onLoopEvent = function( index ) {
           ...
       }
  
       return item; // &lt;--- WAS missing this - as pointed out first by ars265
  }
  
  items[ items.length ] = new Unit();
  
  // main loop that gets called periodically
  function onLoop () {
      for( var i=0; i &lt; items.length ; i++ ) {
      var item = items[ i ];
      item.onLoopEvent( i );
      }
  }
  </code></pre>
  
  <p>I can't see why this is happening. It looks like the method is declared correctly</p>