Meera has posted 70 posts at DZone. You can read more from them at their website. View Full User Profile

Interview: Authors of jQuery in Action

03.28.2008
| 12115 views |
  • submit to reddit

According to Manning, the purpose of this book is to help you learn how to do more on your web application pages with less script. Bear Bibeault and Yehuda Katz, one a jQuery contributor and evangelist and the other an avid and enthusiastic user, believe that jQuery is the best library available today to help you do just that. In this interview to Javalobby, the authors tell us more about their book and jQuery as well.

 

1. Bear, Yehuda, tell us something about yourselves. Who you are, where you are located, and what kind of work do you do?

Bear: Shouldn't there be a microphone? I've alway wanted to be interviewed with a microphone.
Well, I'm a software engineer living and working in Austin, Texas. I've been writing code for over three decades now, and besides having had exposure to just about every production language that?s been popular over the years, I've held positions from junior engineer to development manager.

Right now I've settled into a cozy niche as the architect for a large financial web application that's used by big companies to keep tabs on their internal credit card spending programs.
It's really not as boring as it sounds -- if it were, I'd have died of tedium long ago.

Yehuda: I currently live in San Francisco and work for Engine Yard. We do a mix of Ruby on Rails hosting and Ruby development. I have the good fortune to be working full-time on Merb, an alternate (OSS) Ruby web-framework, which has been picking up steam lately in the Ruby community.

I also get to work on Rubinius from time-to-time. Rubinius is an up- and-coming Open Source Ruby VM, which is based loosely on the Smalltalk-80 VM. It's intended to be fully compatible with the current Ruby interpreter, but be written, as much as possible, in Ruby itself.

2. I see that you have a upcoming book “jQuery in Action”. Is this your first book?

Bear: No, actually it's my third, coming close on the heels of Prototype and Scriptaculous in Action, and Ajax in Practice. I've been writing non-stop for coming on two years now,and I think I'll take a bit of a break and try to remember what the rest of my house outside of my office looks like.

Yehuda: Yep. It's my first book. I contributed two chapters to Ruby in Practice, and am currently working on Merb in Action, all for Manning.

3. Who is your target audience?

Bear: For the jQuery book? Anyone who needs to write JavaScript on their HTML pages. It doesn't matter if it's for simple web sites or wildly complex web applications -- jQuery will make it easier.

Yehuda: It helps to know something about JavaScript, but if you don't, we've included a helpful Appendix to get you up to speed in the areas that are most relevant to jQuery.

4. What is jQuery? Is it a new type of JavaScript library?

Bear: Yes, exactly! In fact, that's precisely how they bill themselves -- as a new type of JavaScript library.

Yehuda: Our original tagline was "New Wave JavaScript", and our original logo was the Devo hat. This was before we had any inkling that we would be remotely successful, of course ;)

Bear: And it does take a rather novel approach. They promote a style of page scripting called “Unobtrusive JavaScript” and the library itself is as unobtrusive as possible.

5.How so?

Bear: Most JavaScript libraries are pretty invasive. They litter the global namespace with a bunch of new variables and “class” names, and some even go so far as to modify the behavior of the native JavaScript objects.

jQuery takes a bit of a different approach. It only defnes two global names, and one of those is even optional!
That conveniently side-steps any pitfalls you can come across with other libraries, like when native objects don't act as expected, or having to worry about what names we canor can't use on the pages.

It also means that jQuery works and plays well with other libraries. If you want to usemore than one at a time for whatever reason, nothing in jQuery gets in the way of doingthat.

Yehuda: jQuery has even been cited by the OpenAjax Alliance (an industry consortium seeking to improve interoperability between JavaScript libraries --http://www.openajax.org) for being a model citizen in this area. We're proud of the way we have made it possible to use jQuery with even the most ill-behaved libraries, and even with libraries who explicitly refuse to work toward interoperability.

6. Why should we be using jQuery?

Bear: Because jQuery rocks!
Seriously, all of the reasons I already mentioned, but mostly because it just makesdoing the types of things we want to do in modern web applications so darned easy! In the book, I called this “doing more with less”. And that's exactly what jQuery brings to the party. You can write a lot less code, and do lot more nifty things on the pages. What's not to love?

Yehuda: Most of the time when writing Ajax applications, you find yourself needing to do something to some collection of elements. jQuery was built around this notion(Jeremy Keith calls it DOM-Scripting), which means that your day-to- day work is also the central mission of the framework.

jQuery doesn't spend tons of time trying to make JavaScript look like another language (like Ruby or Python); it leverages JavaScript's benefits while dramatically improving DOM functionality.

7. What browsers support jQuery?

Bear: It's sort of the other way around. jQuery supports all the modern popular browsers: both isotopes of IE (6 and 7), the Gecko-based browsers like Firefox and Camino, the WebCore browsers like Safari and OmniWeb, and even Opera.

And like any good JavaScript library should, it insulates the page author from having to worry about dealing with all those completely irritating browser differences that drive us all crazy when we're just trying to get stuff done!
This is especially nice in areas like event handling and Ajax where the browser quirk shave always been a royal pain in the keester!

Yehuda: Heh. Yep. My favorite chapter in jQuery in Action is the event chapter, which details how the "jQuery Event Model" works. After detailing the flaws and complexity in the other event models, we show you just how easy jQuery makes it.

8. Can you tell our readers how jQuery works?

Bear: Sure. What makes jQuery so easy to pick up quickly is that most of the jQuery statements follow a similar pattern. You use the jQuery function to select which DOM elements you want to operate on, and then apply the jQuery methods to that set. You can even chain multiple commands to perform complex operations in a single statement.
It's incredibly easy to start being productive with jQuery right off the bat, and then get more and more clever with it as time goes on.

The jQuery selectors, which are simple CSS-based expressions that succinctly let us specify which DOM elements to choose for operating on, are the key to using jQueryeffectively.

Yehuda: jQuery supports almost all of the CSS3 selector set (except for a few arcane ones like :nth-child-of-type that were literally never used), as well as a numberof convenient additions like positional selectors (:lt, :gt, :eq), and form selectors(:button, :text, :radio, :selected).

9. Any tips and tricks for our readers who already are using jQuery?

Bear: Yes. Really spend some time wrapping your head around the jQuery selectors. Learning the methods is easy -- it's using the selectors cleverly that really gives you a lot of bangfor the buck!

Yehuda: I agree 100%. The best thing you can do to improve your utility from jQueryis to learn the available selectors.

Published at DZone with permission of its author, Meera Subbarao.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Mike P(Okidoky) replied on Fri, 2008/03/28 - 12:31pm

My vision of how dynamic database driven websites ought to work is like this:

- the graphic designer mocks up some html pages.  These are raw html files with no special markup whatsoever.  No weird statements inside.  No code stuff inside.  No application server needed to see the mock up page.

- the mock up has each table populated with at least one element.  A table has one row for instance.

- the code would load the page in to memory, and take a copy of each data section's first element, and remove all subsequent elements.

- based on the database data, items get populated by repeating the elements taken from the mock up.

This is the closest way of truly separating design from program.  For the first time in the history of web development can developers hire graphic designers, which do a waaaaayy better job designing websites.  No more clunky crappy developery websites.

I'm seeing in jQuery ways of manipulating the dom.  It also can make ajax calls.  Would it be possible to do this:

- make each web page request be handled by a servlet that inserts the contents of a secondary file into the raw html file.  That secondary file contains all the javascript and jQuery stuff.  I want to keep any of these jQuery instructions and programming gobbledegook away from the designer.  They only thing that's acceptable is id or class attributes, which are needed anyway for the stylesheets.  The result is that the browser is served that html page with a bunch of jQuery script injected in to it.

This really would be THE way to build websites I think.  For years and years, solution after solution, they just didn't get it.  They all failed in my opinion.

I've written two java + javascript based servers that does this sort of thing on the server side.  I worked with a designer, and my designer never saw the application server.  She delivered very nice refreshing little html pages with all sorts of little photoshop bits and pieces, stuff no developer would ever dream of making. 

Bear Bibeault replied on Fri, 2008/03/28 - 8:11pm in response to: Mike P(Okidoky)

Well, the whole concept of Unobtrusive JavaScript pretty much describes exactly what you are talking about. The body markup becomes just that: document markup, with no style embedded (CSS takes care of that) and with no behavior (script) embedded.

I'm not sure that the "servlet injection" step is really necessary. Since the designer is markup-savvy, surely a <script> tag or two in the <head> wouldn't be a problem? 

adam lyons replied on Tue, 2009/01/27 - 10:05pm in response to: Mike P(Okidoky)

IMHO, have fun running a very large website with that kind of retarded dependence. JQuery is for implementing an Ideal User Experience, not an automated lazy inefficient barely scaleable huge cost of ownership  CMS system. Don't use JQuery in places it shouldn't be. There is an ideal place for every brilliant invention, such as JQuery, but i find people over using it and breaking the true Zen it provides for enterprise dynamic web site implementation experts. 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.