Re:Don’t let jQuery’s $(document).ready() slow you down
by Encosia on Thursday August 19, 2010 @10:39AM
(#1617469)
I'm torn when it comes to that. The readability of $(document).ready() is better. Especially for later devs who may not be familiar with jQuery.
Re:Don’t let jQuery’s $(document).ready() slow you down
by billybob on Thursday August 19, 2010 @10:48AM
(#1617493)
For devs not familiar with jQuery (and on the off-chance that you'll need no-conflicts mode at some point), you might even avoid the dollar sign.
jQuery(document).ready(function(){});
Re:Don’t let jQuery’s $(document).ready() slow you down
by JustinSeriously on Thursday August 19, 2010 @01:28PM
(#1617949)
On the other hand, if a dev is that unfamiliar with jQuery code, they shouldn't maintaining jQuery code.
Using $(function(){}); serves as a nice warning to this effect.
Re:Don’t let jQuery’s $(document).ready() slow you down
by rue on Thursday August 19, 2010 @08:05PM
(#1619077)
That is an awful argument. Can you imagine what software would look like if people took that approach with everything? Development would have ground to a halt decades ago.
Re:Don’t let jQuery’s $(document).ready() slow you down
by ganjianwei on Friday October 01, 2010 @01:27PM
(#1747785)
I think the point is that they should learn enough jQuery before maintaining jQuery code.
Re:Don’t let jQuery’s $(document).ready() slow you down
by IgorPartola on Thursday August 19, 2010 @11:29AM
(#1617627)
Or even better:
jQuery(document).ready(function($){});
Re:Don’t let jQuery’s $(document).ready() slow you down
by Encosia on Thursday August 19, 2010 @11:54AM
(#1617697)
You can also use the module pattern[1] to isolate code from tampering or conflicts:
(function($, window, undefined) {
$(document).ready({
// etc.
});
}(jQuery, window);
[1] http://www.yuiblog.com/blog/2007/06/12/module-pattern/
Re:Don’t let jQuery’s $(document).ready() slow you down
by chc on Thursday August 19, 2010 @02:54PM
(#1618199)
Even further off-topic, I really like the succinctness of the former in CoffeeScript:
$(function () {
$('#index').append($('article p:first-child'));
});
becomes: $ -> $('#index').append $('article p:first-child')
Not exactly noob-friendly, but very concise.
I prefer
$(function(){});
to
$(document).ready(function(){});