4 ms·
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(docume
by billybob 16y ago
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(){});
- IgorPartola 16y agoOr even better: jQuery(document).ready(function($){});
- Encosia 16y agoYou 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/ http://www.yuiblog.com/blog/2007/06/12/module-pattern/
- JustinSeriously 16y agoOn 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.
- rue 16y agoThat 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.
- ganjianwei 16y agoI think the point is that they should learn enough jQuery before maintaining jQuery code.