Q: Best practices attaching Event Handlers in large systems I am starting to build bigger things on javascript, and I am wondering about coding style and performance. Now I am trying to figure out what is the best way to attach event handlers in this case: I have Item() constructed objects for which there are divs in the document, one for each, with correspondent ids. I want to have access from each div's event handlers to its item object representation. The items will be manipulated heavily, created, deleted, etc., and so with be their divs. You can look at the code here (any feedback in general coding style would be really appreciated).
I could do this:


*

*By directly having all my event handlers in the Item constructor so
they have access to the object being constructed (var that = this).
I don't think it's such a good idea to have all this code here, but
I might be overthinking this.

*Having the handlers stored in a separate handlerCollection object
and accessing the item object with an auxiliary function
getItemFromDOM(div) which reads the divs id and searches for the
corresponding item in an array where all items in the document are
stored.

*Having somewhere separarte in the code a function
registerItemEvents(item) called in the Item constructor and used to
generate a closure over the item for the handlers, which would live
inside it.
I am guessing the most elegant is the third one, but I might be overrating tidiness turning down the first one. Also is there any chance, using the third, that if I start deleting items the closure over them will prevent memory from being released, ultimately slowing down the whole thing? Can I fix this by simply releasing the event handlers before deleting an item?

A: I think you should consider using delegates, if possible.  From what I know, adding and removing event handlers adds unnecessary overhead.  
Regardless of how you choose to implement (jquery, yui, other, custom), this post from Yahoo! has some good info
http://www.yuiblog.com/blog/2009/11/13/event-delegation-3/
