5 ms·
Griping about jQuery plugins is quite trendy at the moment, which I think can partially be attributed to its audience broading as the lib matures. Most concern
by astrec 18y ago
Griping about jQuery plugins is quite trendy at the moment, which I think can partially be attributed to its audience broading as the lib matures.
Most concerns about plugins and the reputation of their authors apply equally to any OSS software - I wonder how many people acquainted themselves with the author of mod_ssl before loading the DSO into their web server?
Plugin quality does vary, and some of the more popular plugins have become quite bloated as the authors try to cover each and every use case, but the beauty of the license means you can write your own, or strip the bloat/cruft from a plugin that otherwise meets your needs.
jQuery doesn't look pseudo-classical javascript, but that doesn't make it unintelligible gibberish - conversely, I find it a breeze to read and simple, direct and elegant to write.
We're spoilt for choice these days: best to sample as many js libs as you can and stick with whatever feels right.
- Jasber 18y agoMy biggest problem with jQuery plugins is people using $() instead of jQuery(). This breaks functionality for people like me who insist on using jQuery().
- LogicHoleFlaw 18y agojQuery(function ($) { $('#someId').doSomething(); // blahblahblah }); That's my preferred method of invoking jQuery. I get the convenient $() syntax without clobbering namespaces.
- thomasmallen 18y agoSorry, but you're both wrong. Best practice is this: (function($) { // Plugin code }) (jQuery) And you'll see it in UI and most other good jQuery plugins.
- LogicHoleFlaw 18y agoWhat is the advantage of (function($){})(jQuery) over jQuery(function($){}) ? In either case the jQuery object must be in the namespace, and neither leaves a named function laying about. According to the jQuery API jQuery(callback) is sugar for $(document).ready(callback). The ready event is usually when I want my code to run... http://docs.jquery.com/Core/jQuery#callback http://docs.jquery.com/Core/jQuery#callback
- humanchimp 18y agoThe (function($){...})(jQuery) syntax is used by plug-in developers who want their code to run before the jQuery(document).ready event. It is closure, and it's purpose in this case is to protect the global namespace from variables introduced by the script. Closures also have many other useful applications in JavaScript.
- mncaudill 18y agoThis is one technically correct (which is usually the best kind of correct), but the jQuery() invocation has one advantage that I feel makes up for adding "jQuery" to the global namespace which is that the next person that needs to modify my javascript sees my code, they'll see the jQuery right up front and know what's up.
- thomasmallen 18y agoThat's what comments are for :^) I always make the dependency pretty clear in my scripts. Plus, it's a "best practice" in the jQuery community to name your plugins in the form jquery.plugin.js or jquery.package.plugin.js.