This is a technique that uses closure. The idiom is well-known, but confusing when you first see it. FOO
is defined as the object that the outermost function() returns. Notice the parenthesis at the end, which causes the function to evaluate and return { hash }
.
The code is equivalent to
function bar() {
...functions() ...
return { hash }
};
FOO = bar();
So FOO is equal to { hash }
. The advantage of this is that hash
, whatever it is, has access to stuff defined inside the function()
. Nobody else has access, so that stuff is essentially private.
Google 'Javascript closure' to learn more.