Class Inheritance and jQuery
03 10 08 - 13:40 A post over at CNET Clientside Blog* (Aaron Newton) got me thinking...jQuery gets a unfair bad rep for extensibility -- the sheer popularity of jQuery means that a large number of users aren't using jQuery to its full potential. I develop with jQuery the same way Aaron develops with MooTools -- when I see a pattern emerging, I create a plugin and extend jQuery. It's simple to create your above example -- just use jQuery.extend! (More detailed example here.)
He mentions to call a plugin method, the code would be:
"jQuery(domId).pluginName(”methodName”, [arg1, arg2]); - I hope I have that right."
It can be that way, but with a properly designed plugin it's as easy as:
$(domEl).plugin.method(arg1,arg2);
...And if you want full class behavior, with super/subclasses etc., Resig has thought of this as well:
http://ejohn.org/blog/simple-javascript-inheritance/
Also, it's been done for production. Here's a good read, a recent post about this exact topic by Dr. Danny Wachsstock.
Most of all, check out Dan Webb's port of Low Pro to jQuery.
The class issue has been discussed at length -- and solved -- in the Groups and other various forums. Therefore, I fail to see 'what really makes one framework different from another'... except that jQuery is much less verbose! Aaron's MooTools code (in the post) is nearly identical to jQuery -- except the 'addEvents' drive me nuts, thank goodness for .click() and other jQ event methods.
I think Resig feels much the same way I do about how class-based design can often be overly descriptive, and a waste of bytes.
In all seriousness, I don't want to start a flame war or framework competition any more than Aaron does. I just realized that there's so much to jQuery, even the Ajax Experience can't cover it all!! -- So I hope this brings to light another strength of jQuery and stops some FUD.
*[link corrected 10-Oct as per Aaron's comment below]
Charles
Trackback link:Please enable javascript to generate a trackback url