var obj = {
func: function() {
return: {
add: function() {
}
}
},
somefunc: function() {
An anonymous function that is executed immediately is commonly used to create a scope. Any variables that you declare inside the scope is local to the function, so they don't pollute the global scope.
The return statement is used to return an object from the anonymous function:
var hash = (function() {
return { ... };
})();
You could write the same using a named function:
function createHashObject() {
return { ... };
}
var hash = createHashObject();