This answer to another question really helped me expand my understanding of how javascript objects work:
http://stackoverflow.com/questions/1007340/javascript-function-aliasing-doesnt-seem-to-work/1162192#1162192
As for your code snippet, let's break it down. Start by looking at the high-level structure: var foo = ( exrpession );
. You could just as easily say: var foo = expression;
, but IIRC the parentheses are needed to handle an IE-specific quirk.
Now, in this case the expression is an anonymous function. Javascript is perfectly fine with you defining a function with no name. Just don't expect to call it unless you save a reference some where. You can also call an anonymous function immediately after the declaration, like this:
function() {
alert('test');
return 42;
}();
This should look suspiciously similar to the basic structure used for the expression from your code snippet. Hopefully you can easily see that the 42
from my sample could just as easily be an object.
So the question remains, why would you do this? Remember that in javascript, functions are also objects. As a good student of OOP, you probably like to make some members of your objects private. However, javascript doesn't have anything built-in to support this. Fortunately, it just happens that if you return an object from that inner function it will have access to other variables defined in that function, but outside code will not have any way to access them. So you have, in effect, created an object with private members.