Andrew Dupont's Mix 2011 presentation shares his experience with working with messy JavaScript and how to work towards maintainable JavaScript. He covers separation of concerns, using custom events, MVC, templating and developing modular code.
Christian Heilmann lays out seven rules to better unobtrusive JavaScript, including not making assumptions about JavaScript, the browser and the document. Work with structured markup. If you are traversing a document, maybe there's a solution that can take advantage of CSS's selector mechanism instead. Work with browsers and users. Better understanding of events, and playing nice with namespace, scope, and patterns. And of course, think about the next developer, so keep the code maintainable.