title: javascript: use of 'this' in object literal function giving an error
body: <p>I'm having to fix up a megamenu system for a site I've been handed, and I've run into a bug.</p>
  
  <p>Once the DOM is ready (jQuery is included) the megamenu's render function is run. Within this there a listener is added for resize to rerun this function, re-rendering the code. However, I'm getting javascript errors that think that this render function when called from within the object is actually a function of the window so I get <strong>"Uncaught TypeError: Object [object DOMWindow] has no method 'render'"</strong>.</p>
  
  <p>But the function runs anyway!</p>
  
  <p>here's a brief snapshot of the code:</p>
  
  <pre><code>var jkmegamenu=
  {
   ...
      render:function($)
      {
      ...
          $(window).bind("resize", function()
          {
            this.render($);
          }
  
      }
  
  }
  </code></pre>
  
  <p>Now I've tried <strong>jkmegamenu.render($)</strong> (don't know what the dollar is for, works with or without due to jQuery I imagine), and I've tried defining self as <strong>self: this</strong> but the same error occurs. Its a fairly large file and I'm pretty busy so I'm only considering recoding it a proper jQuery object (e.g. <a href="http://www.phpied.com/3-ways-to-define-a-javascript-class/" rel="nofollow">http://www.phpied.com/3-ways-to-define-a-javascript-class/</a>) if thats the only other option, otherwise does anyone know a quick fix?</p>
  
  <p>The site is kent.ac.uk and you'll be able to see the errors popping up, especially on resize.</p>