rajeemcariazo
rajeemcariazo

Reputation: 2524

What is the meaning of jQuery enclosure in Javascript libraries?

I see a lot of third party javascript codes that are enclosed with jQuery like this:

$(function() {
  // ... javascript code
});

What is the purpose of enclosing with jQuery?

This is different from $(document).ready(function() { /* ... */ }); right?

Upvotes: 2

Views: 320

Answers (1)

Buzinas
Buzinas

Reputation: 11733

This is different from $(document).ready(function() { /* ... */ } ); right?

No, it's only a shorthand. They are exactly the same, as you can read on jQuery's website:

All three of the following syntaxes are equivalent:

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

Upvotes: 3

Related Questions