

Ultra-Chaining with jQuery - qhoxie
http://ejohn.org/blog/ultra-chaining-with-jquery/

======
aston
My one and only gripe with jQuery is the heavy emphasis on chaining method
names on top of method names. Sure, the code you get out is terse and
relatively readable, but you're not coding Javascript anymore. And Javascript
is too cool not to code in, given the chance. Just ask the people writing your
frameworks...

~~~
thomasmallen
But you are coding in JavaScript. You just make sure that your methods return
the current object if you want them to be chainable.

The real JavaScript of jQuery doesn't happen when you're writing simple
transformations on the page, instead, you really get deep into it once you
start extending jQuery through plugins. To really write these correctly, you
need a deep understanding of JavaScript (because you'll be reading the jQuery
source code at many points).

More than anything else, jQuery is an API to make the DOM manageable (itself
an API of sorts).

What's great about JavaScript in many ways is that it's not Python (which is
also great in so many ways): It's very flexible and lets you write your code
as you see fit. I don't think that jQuery could happen so easily and cleanly
in many other languages.

But any serious object-oriented language needs to be able to method chain, and
it needs to feel natural. Even PHP can do it (I used this in a template engine
to generate HTML structures very quickly):

    
    
      $template->div("#header")->ul()->li()->a("A new link");

