JQuery » jQuery UI v1.5 Released, Focus on Consistent API and Effects
jquery.com
jquery.com
# $(”div”).draggable(”destroy”) destroys it
Am I missing something here, or is that an extremely ugly design choice? Passing strings into functions to specify what function you want? eugh
jQuery('div:first').addClass('hello').text('Hello World').draggable().css('color', 'red');
If a plugin needs three or four methods, that's three or four extra functions on the one object - which ends up looking quite ugly:
jQuery('blah').draggable({options}).destroyDraggable()
The message passing idiom lets them add just one method to the jQuery.fn namespace that can cover a full range of different actions. I think it's a pretty clever pragmatic solution.
If you call a.destroooooy() then you'll get a js error, but if you call a.execute("destroooooy")...
I wonder however if a plugin could define its own namespace, like:
$('blah').draggable().create({options}).css(..)...
$('blah').draggable().destroy().css(..)...
draggable() returns a wrapper that exposes only the dragging specific methods, but the underlying jQuery is passed through and returned by any method called on the wrapper. That way you don't have to add all methods in the same namespace.On second thought I don't know if this wouldn't just be confusing :-)
The interesting thing about jQuery is its focus - it almost exclusively works to improve the interaction between JavaScript and HTML. DOM manipulation is more convenient in jQuery than any other library, and the other library features build on top of that core ideal.
mooTools and Prototype attempt to make improvements to the JavaScript language. jQuery tends to play along with the language - it supports a functional style of programming using lots of closures (while you can avoid them if you really want to I find jQuery code with closures flows really well).
$('div').draggable().create({Object hash}).draggableDestroy();
It may look awkward at first but I think it will a result into a new win in the long run. I'm having alot of trouble downloading the new library for some reason but can you do something like this?
$('div').draggable().create({Object hash},function(){ alert(Object Creation confirmed}; ).draggableDestroy();
I think the ability to launch a callback function on the creation of a object could open oppurtunities for better UI feel and responsiveness.