Where to Keep Event Handler code, in namespace objects or closures?
<p>In the last couple of years I've been using JavaScript name spaces espoused by YUI as my default way of formatting JavaScript code.</p>

<p>All in all it works well in more complex environments where many web widgets may be stuck together at different times.</p>

<p>Until recently I've almost always used added event handlers in the HTML by calling the handlers from the name spaced object itself.  </p>

<p>I've been using JQuery lately and have been setting the handlers inside of the ready function rather than in the HTML.</p>

<p>As I do more and more of that it seems that the closure of the JQuery ready function is taking the place of the name space object.</p>

<p>What I am ending up with now (at least for one widget/tool type pages) is a name space object that primarily deals holds data and a bunch of closed event handlers that I access the name space object for data specific purposes.</p>

<p>My question is, what are some best practices for dealing with closures verses a Name space object particularly as it relates to event handlers?</p>

<p>Or, similarly, what are some best practices for setting up event handlers, should they be "heavy weight" and handle the processing themselves, or hand off to more library like code.</p>

<p>Personally it's harder to keep track of the flow of many separate "heavy weight" event handlers.</p>
