Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've been enjoying Lynda.com's Jquery Essential Training, and I've noticed that in the beginning the instructor uses:

    Fig. 1

    $("document").ready(function(){
    fun stuff goes here
    });

However, somewhere along the line he starts using:

    Fig. 2

    $(function(){
    fun stuff goes here
    });

From the way he speaks, it sounds as if they are completely synonymous (some inherent jquery shorthand?) but as far as I can tell, it's never explicitly touched upon.

I'm sure someone could clear this up quickly for me. I found this but I believe that question is slightly different--I understand the concept of calling a function on document ready versus one that is globally available; (those functions also have names.)

The instructor uses phantom functions (I think that was the term for a function without a name,) and when typing out Fig. 2, he says "So this will be on document ready..."

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
253 views
Welcome To Ask or Share your Answers For Others

1 Answer

Yes, they are exactly the same, just aliases.

From the jQuery site:

All three of the following syntaxes are equivalent:

$(document).ready(handler)
$().ready(handler) (this is not recommended)
$(handler)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...