Shortcuts for jQuery's ready() method
Solution 1:
The third option is not a shortcut for .ready()
(or jQuery related really), the self invoke runs immediately (as soon as it appears in the code), this is probably the shortcut you're thinking of though:
$(function(){
alert("I'm a ready shortcut");
});
Passing a function into $(func)
is a shortcut for $(document).ready(func);
. The no-conflict version would look like this:
jQuery(function($) {
//$ is jQuery
});
Solution 2:
Nick Craver is right in what he says but I think it is worth noting that in that last example that it isn't actually doing anything with jquery at all. jQuery is being passed as a parameter to the anonymous function but the function isn't doing anything with it.
The last example is equivalent to an Immediately-Invoked Function Expression (IIFE):
(function(){
alert("self invoke");
})();
And clearly this is just immediately calling the anonymous function as soon as that line of code is being hit and thus doing the alert. It isn't invoking jQuery at all which is why Nick is right when he says it is defintiely not a ready() method.