Is
$(document).ready(function(){});
the same as
$(function(){});
?
I believe it is, actually I'm 开发者_运维知识库99% sure it is but wanted a 'second' opinion
Yes it is the same.
From the jQuery Docs - http://api.jquery.com/ready/
All three of the following syntaxes are equivalent:
• $(document).ready(handler)
• $().ready(handler) (this is not recommended)
• $(handler)
Yes
"the document-ready
idiom is so common, in fact that there's a shortcut version of it... The expanded version $(document).ready
is arguably a better example of self-documenting
code; it's much easier to see at a glance exactly what's going on - especially if it's buried in a page of another developers JavaScript!" - Borrowed from - jQuery Novice to Ninja
Indeed it is. Personal preference.
精彩评论