I think they ended up having to do that because of jQuery's chaining support. Most of jQuery's functionality lives in a single namespace (jQuery.fn) which means you can chain method calls together like this:
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.
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 :-)
Sure. I still think it's ugly though. It reminds me a lot of an old coworkers code.
He decided to simply expose one method to his subsystem - .execute(String what, String[] args)
Then you would pass in strings to specify what you wanted it to do. It made my brain hurt for weeks.
I don't see how it is more like message passing than an ordinary method call? Only difference AFAICT is that since JS don't support "catch-alls" (yet), you can't handle missing methods at the receiver. But that does not seem to be relevant here.
# $(”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