I read the following on the web this weekend and I wanted to know if most others consider this the right (better) way of doing things.
This is not the best (right) way to do things:
$(document).ready(function() {
$('#magic').click(function(e) {
$('#yayeffects').slideUp(function() {
// ...
});
});
$('#happiness').load(url + ' #unicorns', function() {
// ...
});
});
That this is better:
var PI = {
onReady : function() {
$('#magic').click(PI.candyMtn);
$('#happiness').load(PI.url + ' #unicorns', PI.unicornCb);
},
candyMtn : function(e) {
$('#yayeffects').slideUp(PI.slideCb);
},
slideCb : function() { ... },
unicornCb : function() { ... }
};
$(document).ready(PI.onReady);
Does one perform better than the next? Easier for debugging?
Thoughts? Comments?
$(function(){...})is equivalent to$(document).ready(function(){...})