Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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");




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: