I'm curious as to if there are any best practices relating to JQuery when constructing encapsulated code blocks.
Generally, when I construct a page I like to encapsulate the functions used within that page inside an object. This allows me some encapsulation when building applications. There's nothing I hate more than seeing a JavaScript file with a bunch of this
function doSomethingOnlyRelevantOnThisPage() {
// do some stuff
}
I this makes for messy design, and doesn't really encapsulate functionality nicely.
Commonly in many frameworks, there is a standard that is used to perform this encapsulation.
In Mootools they favor the Object Literal Notation:
var Site = {
// properties and methods
}
In YUI they favor the Self Executing Function notation:
(function() { // properties and methods })()
The nice thing about the second example is that a closure is created, thus allowing you to define private properties and methods.
My question is this: Do any JQuery aficionados have any best practices for creating these cleanly encapsulated structures? What is the rationale behind their use?