tags:

views:

80

answers:

1

Can someone tell me the difference between:

$(document).ready(function() {

});

and:

var someVar = {
    ready : function() {
    }
}

or:

$(function() {
});

I have seen things started in all three ways and I am never sure which way to start. Is it different for different situations or uses?

+10  A: 

Your first and third examples are identical - jQuery offers the third syntax as a shortcut for the first one. Your middle example creates an object literal called someVar that has a ready method (this doesn't really have anything to do with jQuery).

Andrew Hare
+1 for great minds think alike!
thephpdeveloper
Ah. Well I guess it is easy to think the middle one did have something to do with JQuery as it has the ready : function() in there and I see it used on any number of JQuery tutorials. I like the last one anyway. Shorter .. less code.ThanksDave
Dave