Differences between 2 pieces of code (anonymous functions)

Differences between 2 pieces of code (anonymous functions)


Hi,
I've been reading the jQuery documentation, the authoring plugins
section and I'm confused about the whole hidden functions thing.
Question #1:
(function($) {
// CODE
})(jQuery);
This was the thing that got me most confused when reading the
documentation. Can someone explain me:
a) What it does
b) What is it for
c) The best scenarios where would I need to use something like this
Please explain me these like if I was really dumb :P
Question #2:
How is this:
(function($) {
$.something = function() { alert('something'); }
$.test = {
abc: function() { alert('test'); }
}
})(jQuery);
Different from this:
jQuery.something = function() { alert('something'); }
jQuery.test = {
abc: function() { alert('test'); }
}
Besides the syntax used of course... I mean, you simply do
$.something() or $.test.abc() and it will work no matter if you opted
by coding like in the first syntax or second.