Follow Slashdot stories on Twitter

 



Forgot your password?
typodupeerror
×
Image

Learning JQuery 1.3 153

Michael J. Ross writes "Of all Web technologies, JavaScript may have the most checkered past — first heralded as a powerful object-oriented language for jazzing up Web pages, but later condemned as a source of spammy pop-up windows and horrid animations polluting websites everywhere. Yet during the past several years, Web designers and developers are increasingly using JavaScript unobtrusively, for client-site interactivity — as a supplement to server-side functionality, not a replacement, and built upon standards-compliant (X)HTML and CSS. As a result, the once-derided language is now enjoying a true resurgence in interest and use. This has been bolstered by the proliferation of JavaScript libraries, of which jQuery is clearly the front runner. Web programmers seeking to get up to speed on this exciting resource can turn to Learning jQuery 1.3: Better Interaction Design and Web Development with Simple JavaScript Techniques." Keep reading for the rest of Michael's review.
Learning jQuery 1.3
author Jonathan Chaffer, Karl Swedberg
pages 444 pages
publisher Packt Publishing
rating 9/10
reviewer Michael J. Ross
ISBN 978-1847196705
summary A detailed introduction to this popular JavaScript library.
Written by Jonathan Chaffer and Karl Swedberg — two veteran Web developers based in Grand Rapids, Michigan — Learning jQuery 1.3 was published on 13 February 2009, under the ISBN 978-1847196705, by Packt Publishing, which kindly provided to me a copy of the book for review. There is a publisher's Web page for the book, where readers can order print or PDF versions of the book (or both, at a sizable discount); contact Packt Publishing with questions or feedback; read more information about the book, the authors, and the table of contents; and download a free sample chapter (the fourth one, titled "Effects") in PDF format. Readers who want to follow along with the authors' discussion, should note that all of the sample code used in the book can be downloaded from its support page. There is also a link for reading the reported errata, of which there are eleven, as of this writing. (The erratum for page 40 is incorrectly listed twice.)

The book begins with a foreword by John Resig, the creator of jQuery. What follows is over 400 pages of information, organized into eleven chapters and four appendices, covering all of the major topics related to jQuery, after a quick-start chapter: selectors, events, effects, DOM manipulation, AJAX, tables, forms, shufflers and rotators, plug-ins, online resources, development tools, and closures. The book has all the ingredients to serve as a full introduction to jQuery for experienced Web programmers, because it assumes no prior knowledge of jQuery (or any other JavaScript libraries); but it does assume that the reader comprehends the basics of HTML, CSS, and JavaScript — thus not wasting time by teaching these prerequisites skills, as is attempted in some other Web programming books.

The first chapter may be brief, but it is sufficient to present the major features of jQuery, its advantages versus raw JavaScript, and a quick history of its various releases after it was first mentioned by John Resig in August 2005. In addition, the reader is shown where to obtain the library, how to add it to a Web page, and a few of its basic capabilities. In the given example, multiple HTML paragraph elements are styled using just three lines of code; yet the power of jQuery would have been demonstrated even better had the authors also shown the equivalent raw JavaScript needed to perform the same functionality.

The next four chapters present the basics of jQuery upon which everything that follows is built. Readers are introduced, in Chapter 2, to the jQuery syntax for accessing individual elements and groups of elements on a Web page, using the $() factory function, CSS selectors, and jQuery's own custom selectors. As with all of the chapters that follow, several examples are used to illustrate the core ideas. The ability to intercept and react to events on a Web page — such as a user clicking on a particular link — is an essential part of client-side interactivity, and is the topic of the third chapter. But first the groundwork is set by learning how to control when code is executed, how to utilize multiple scripts on a page, and how to use jQuery with other JavaScript libraries. Then a style switcher example is used to demonstrate the "this" keyword, shorthand event methods, and compound events, as well as event capturing, bubbling, objects, targets, propagation, delegation, namespacing, and other topics. Unfortunately, the screenshots are of little help, largely because the black-and-white images fail to show user feedback, such as green backgrounds on hover, and even bolded link text. Chapter 4, which covers jQuery effects, begins by explaining how to programmatically discover and save attribute values, for later use; then it explains how to hide and show HTML elements, fade them in and out, toggle their settings, create simple custom animations, invoke effects sequentially using queuing, and queue effects on different elements using callback functions. The fifth chapter shows how to easily add and remove elements and their attributes from the DOM, and even create a new DOM structure from scratch. Most of the sample code is well explained, except for the fourth line in the insertAfter() snippet on page 96, which is not clear at all. Also, the sample text that consumes the bulk of pages 98 and 99, should be replaced with something much shorter, partly because it would be easier to locate the "span" tags within the text. This chapter, like the previous one, concludes with a "nutshell" summary that is quite helpful — and would be even more so if it listed, next to each jQuery method, the corresponding page number.

Asynchronous JavaScript and XML (AJAX) is a combination of technologies that is seeing more widespread use every year, as developers discover the advantages of dynamic Web page interactivity without the reloading of the page each time, which of course slows down the process for the user. The sixth chapter shows how to utilize AJAX, from a jQuery perspective, with explanations and examples of the four major approaches that involve static data files, including a handy summary of when each approach would be most appropriate. Also explored are the dynamic AJAX strategies, including GET and POST requests. The authors should have mentioned that, in order to make functional the "E" and "F" dictionary entries in the example, the reader will need to load the index.html file using a Web server, and not as a static HTML file, so the calls to "e.php" and "f.php" will work. By the way, anyone confused by the reference to jQuery Reference Guide, on page 146, should be aware that it is the title of a book written by the same authors as this one.

With the seventh chapter, the authors transition from what they consider to be the tutorial portion of the book, and begin to demonstrate how the reader can utilize the earlier basics for improving Web page functionality — in this case, working with tables. The authors make good use of code snippets and screenshots to show how one can do table sorting, row striping, row highlighting, and other capabilities independent of — and in conjunction with — server-side equivalents. The subsequent chapter consists of a similar survey of jQuery goodness, but applied to forms — specifically: styling, client-side validation, auto-completion of search entry fields, and input masking (with an emphasis upon numbers). The sample HTML is a model of quality markup, except for the wrapping of checkbox input elements inside of label elements, which is noncanonical and can make it problematic to properly align all the checkboxes in a form vertically, for all browsers. Chapter 9, titled "Shufflers and Rotators," demonstrates how to create a rotator for RSS newsfeed headlines, and an image carousel featuring image enlargement with transition. Readers interested in testing out the sample code — and possibly even modifying it — should be aware that, for chapters 7 through 9, the sample code within the downloadable archive is not stored in chapter-named directories, but instead combined into an application, in the "bookstore" directory.

The last two chapters of the book are devoted to jQuery plug-ins — using those created by others, and developing one's own. In Chapter 10, to illustrate the high-level ideas, the authors focus on and recommend a number of specific plug-ins built for handling forms, advanced effects, widgets, tables, images, and charts, as well as some theming resources. In the subsequent chapter, the authors show how to develop plug-ins of varying complexity, including those that implement new global functions, implement new jQuery object methods, and extend the jQuery selector engine; the chapter wraps up with advice on how best to distribute newly-created plug-ins.

All of the chapters end with summaries, which, given the detailed and technical nature of the material within each chapter, do not add any value to the book, and could be excised without loss. The four appendices offer some valuable information: numerous online resources for readers seeking reference material; development tools for the most popular Web browsers; details on JavaScript closures; and a quick reference for the jQuery selector expressions and all of the methods. The weakest part of the book, the index, is inadequate — missing important terms, such as "animation," "callback," "iteration" (or "iterator"), and "toggling."

The following errata have yet to be listed on the book's support page: "Let[']s" (page 23), "page [is] loaded" (page 40), "if Normal was" (should read "if Normal were"; page 61), ", though" (should read "though,"; page 80), "user the $() factory function" (page 113), "slices with be" (page 283), and "though[,] there" (page 340). In the errata listed on the support page, the entry for parseFloat refers to page 74, but the error actually occurs once on page 69 and twice on pages 70, 71, and 79. In the six screenshots on pages 253 through 257, the shipping totals are incorrect. Nevertheless, the number of errata per page is far less than what is found in most computer books, especially those from Packt Publishing.

The generous amount of sample code should be quite helpful to the reader, because for most programmers, we learn best by example. However, there are many instances where a line of code is unnecessarily wrapped to a second line, even though there is plenty of room at the end of the first line to accommodate the portion of code forced down; pages 82 and 217 have glaring examples of this. The same premature wrapping is seen in some of the text, such as on pages 210 and 311.

The authors as a whole do an admirable job of explaining the central ideas. The explanations are generally clear, which is absolutely critical for a topic like jQuery that can be overwhelming to anyone unfamiliar with it — and not just as a result of the somewhat cryptic syntax (which admittedly is unavoidable), made worse by chaining and especially by the nesting of anonymous functions. Even a cursory glance through the book should make evident that the authors put a lot of effort into writing it, reflected not just in its substantial length, but also the number of examples they created for the book, and the functionality contained therein.

With its thorough coverage of key jQuery topics — from the basics to plug-in development — Learning jQuery 1.3 is an information-packed resource that can help Web developers learn how to take their JavaScript programming to the next level.

Michael J. Ross is a freelance website developer and writer.

You can purchase Learning jQuery 1.3 from amazon.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

*

This discussion has been archived. No new comments can be posted.

Learning JQuery 1.3

Comments Filter:
  • Wow (Score:4, Funny)

    by El Lobo ( 994537 ) * on Monday January 11, 2010 @11:19AM (#30724146)
    Key, then, to learning JQuery this book is.
  • HTML forms (Score:2, Insightful)

    by Anonymous Coward

    Client side form handling is the browsers job.

    Roll on HTML 5 [diveintohtml5.org]

    • Re: (Score:2, Funny)

      by toastar ( 573882 )

      indeed, I thought HTML 5 was supposed to magically make Javascript and other client side scripting languages*Cough*Flash*Cough* go away.

      • Re:HTML forms (Score:4, Insightful)

        by Tablizer ( 95088 ) on Monday January 11, 2010 @01:01PM (#30725626) Journal

        The problem is that HTML was originally designed for "e-brochures" more or less. It doesn't fit desktop/CRUD-style GUI's very well and people have been trying to tack that on after-the-fact with D+ results which are bloated, buggy, jittery, and version/brand-sensitive.

        In my opinion, we need a new kind of browser that is designed to handle desktop/CRUD GUI's well from the get-go. Most of the features we know and love from desktop/CRUD GUI's would be specified by mere mark-up and wouldn't have to download entire GUI system kits to emulate them. Client-side scripting would then be for rare specialized stuff it can't handle. Force-fitting is just not working well and we've been at it for more than a decade. Let's stop trying to paint stripes on a horse and just go get a real zebra.
               

        • by reed ( 19777 )

          On the other hand, the *lack* of a standard WIMP GUI toolkit for web pages has also let loose a few creative ideas for what a UI could be. The standard desktop GUI toolkits make it easy to write mediocre and somewhat boring UI's that get the job done but not very elegantly or ergonomically, and which all look exactly the same.

          Web apps are not really a blank slate... but they could be close once you decide what parts of the HTML/browser framework you intentionally *don't* want to use and step around.

          (HTML5

        • by Rysc ( 136391 ) *

          We already have that browser, it's called Firefox. And we all ready have a desktop-style-GUI-builder markup language, it's called XUL.

          If you assume you're writing for an XUL-aware browser then 90% of what you need is there and has been for years. Not to say that XUL couldn't use some work. In the real world it would never be adopted cross browser as is but it could serve as the basis for a proposal for a standard markup language intended for this purpose.

  • by Camel Pilot ( 78781 ) on Monday January 11, 2010 @11:26AM (#30724220) Homepage Journal
    I have been learning jquery lately. I am still uncomfortable about the functional programming paradigm. I really hate the way it creates highly indented code. At the end of some complex operations with several anonymous functions as arguments you end up with scads of )}: characters and it is easy to get lost in the indentation.
    • by ByOhTek ( 1181381 ) on Monday January 11, 2010 @11:35AM (#30724318) Journal

      So, don't make them anonymous. Problem solved.

    • Re: (Score:3, Insightful)

      by rob_osx ( 851996 )
      The name "functional programming" implies the use of functions, yet I've seen too much "functional programming" that is just lines and lines of indented code. Here is an idea: Actually create new functions! Yes, these innovative routines can actually make the code readable and encourage code reuse! Try to make each function do one task, and code will be readable, reusable, and will not suffer from over indention.
      • Re: (Score:3, Insightful)

        by Nadaka ( 224565 )

        No. Functional programming does not just "implies the use of functions". Functional programming applies only to languages that consist of stateless atomic functions exclusively. The word you are looking for is "procedural programming"

        • by slim ( 1652 ) <{john} {at} {hartnup.net}> on Monday January 11, 2010 @12:17PM (#30724962) Homepage

          You can do functional programming in languages that don't enforce functional programming.

          The GP makes the valid point that people sometimes use anonymous functions when a named function would be clearer.

          Instead of (hypothetical language):

          myList.map({ // some complex inline anonymous function
          });
          ... instead ...

          function transform { // some complex code
          }

          myList.map(transform);

          It can increase clarity, and reduces the depth of indentation the GGP was complaining about.

          • Re: (Score:3, Informative)

            by Nadaka ( 224565 )

            That is technically accurate, you can do functional programming in languages that do not enforce use of stateless atomic functions... If you are able to ensure that you only use stateless atomic functions and none of the functions/objects you use in the language alter the programs state. In practice, that means being confined to a fairly small subset of the language in question and it may be impossible in some languages.

            His definition was still clearly referencing procedural programming.

    • Anonymous functions. Eww!

      Don't, just don't!
    • by Tablizer ( 95088 ) on Monday January 11, 2010 @12:16PM (#30724946) Journal

      I think there's some "faddism" to the recent functional programming (FP) push. FP has a place, but that place is not necessarily everywhere. We learned the same lesson with OOP: some parts of our software fit it well and some don't. Use the right tool for the job. Some if it is also subjective. We all think different.

      There will be some zealots who will say, "Your entire program must use X-oriented programming or you are a lame dumb Luddite who doesn't get it. Puppies will die of cancer if you don't use only X". But these extremists will tend to fall by the wayside and people will end up using different paradigms where they work best as experience teaches when to use what.

    • I have been learning jquery lately. I am still uncomfortable about the functional programming paradigm. I really hate the way it creates highly indented code. At the end of some complex operations with several anonymous functions as arguments you end up with scads of )}: characters and it is easy to get lost in the indentation.

      It's the deficiency of (overly verbose for an FP language) JavaScript syntax, not FP itself. If you look at Ruby, for example, it specifically has some syntactic sugar to make it possible to write FP code that looks like "normal" control structures. E.g.:

      xs.each { |x|
      puts(x)
      }

      It's actually an invocation of method "each", passing it a single-argument block (closure) as an argument.

    • I also get annoyed with this style of programming. While I try to while things in more explicit form when using jQuery to make debugging easier for myself, pretty much all the examples on the web are written in this terse, yet not so readable form.

  • JQuery (Score:3, Insightful)

    I looked into JQuery recently for a web project, and while it is really, really cool, it's pretty heavy if all you want is (say) a Calendar popup. I think JQuery is really useful if you are going to basically do a desktop-style application using Javascript, like a spreadsheet or other major application. If all you want is a few controls for standard web forms, JQuery is overkill and too slow to download. There are better individual choices.
    • Re:JQuery (Score:5, Insightful)

      by royallthefourth ( 1564389 ) <royallthefourth@gmail.com> on Monday January 11, 2010 @11:30AM (#30724274)
      It's only 19kb and that tiny transfer only happens once because of browser caching. It's not too big for anything.
      • It's only 19kb and that tiny transfer only happens once because of browser caching. It's not too big for anything.

        Maybe you got it down to 19K, but when I tried to do something actually useful (like the aforementioned Calendar popup), the sum of all the various components was pushing 70-80K (yes, using the compressed versions). Maybe there was some trick I wasn't using to get it down that small -- I wish there was, because I did actually want to use it. The JQuery site isn't the most straightforward in th

        • Re:JQuery (Score:4, Informative)

          by Mr. DOS ( 1276020 ) on Monday January 11, 2010 @12:09PM (#30724812)

          19KB is an "I-wish" number. To actually get that size, the web server has to be gzipping output, a feature that isn't always on or available. Minified alone, the base jQuery library is 56KB. That's probably where the majority of your size was coming from.

                --- Mr. DOS

          • Minified alone, the base jQuery library is 56KB. That's probably where the majority of your size was coming from.

            And on 28k dialup (which some people - like me at one site - are lucky to get) that's 20 seconds (more with TCP turnarounds).

            • Make that 16 seconds plus turnarounds and miscelaney. (Can't do simple arithmetic this morning.)

            • Oh, I wasn't disagreeing - my home was on a 48k dial-up connection for a six-year period that only just ended in the last week of October. I was simply trying to explain why 19KB is less likely than the jQuery team seems to make out.

              On a related note, accessing /. on dial-up raises a funny point about the new Slashcode comment system: the slowness of the site is not so much due to the size of all the resources, but due to the amount of CPU time it takes to handle the CSS and JS.

              --- Mr.

          • Also, I'm wondering if there is caching going on for this. If not, it could be as bad as 56KB every page without compression.

            Also, I thought any container that was configured by someone with half a brain knew how to setup compression. I was one of those less-than-half-brain-folks as recently as a month ago, so it happens. I never did the initial configuration of Tomcat/Apache, just never bothered looking at how it was configured.

            Compression + proper caching means your jqueryMini.js is a one-time 20KB hit.

            • I can't remember whether or not the default Apache configuration has compression enabled or not - it's been a while since I installed a web server. This matters because I'm sure there are many less-than-half-brained folks who leave the majority of httpd.conf in its default state and jump straight to setting up virtual hosts.

                    --- Mr. DOS

        • Considering most Slashdot pages climb to over 1MB ... YES, 1 whole megabyte ... 19k or even 70-80k would be a Godsend.

        • I tend to just use jQuery core and write everything else on top of that from scratch.

          I don't usually bother looking at using jQuery addons unless trying something really tricky, I can write much leaner code myself for highly specific purposes than I would be able to accomplish by bolting together some generalized components.

          I'm not sure where the GP got 19KB though, unless it's a really old version. Current version is 54KB "minified", which is what people should be using. Prior to 1.3.x, they used to prov

    • There might be some confusion here. You're referring to JQuery UI, which is not the same thing as the core JQuery language. 19kb is referring the gzipped, minified version of JQuery. What you're seeing is probably the JQuery UI script (which is pretty large, even if you cut out the extra stuff).

      If you just want a simple calendar, I've found Unobtrusive Date Picker [frequency-decoder.com] to be quite nice. It also doesn't take up a whole lot of space, AND is keyboard friendly! Oh, and it plays nice with JQuery (a big plus).
    • Yes, JQuery has some nice ui stuff in one of its additional libraries. But the primary purpose of JQuery is for the AJAX support. Using it, you don't need to sit and worry about browser compatibility. It's also a lot easier to find and manipulate DOM objects.
    • How is jQuery 'clearly the frontrunner'?... Has this reviewer never heard of ExtJS?

      It bothers me how overcomplicated everyone makes the use of asynchronous connectivity on a web page, and how wasteful it is to use XML to communicate with yourself.

      None of these frameworks are easy to use.. you're better off learning a few key pieces and using a minimalist/obscure approach and remove XML from the AJAX equation. The filesize of some of these frameworks are 50% wasted on encoding/decoding XML when plain deli

      • by mcvos ( 645701 )

        Maybe jQuery is the frontrunner because everybody is tired of XML and wants to use JSON instead?

  • by Anonymous Coward on Monday January 11, 2010 @11:30AM (#30724268)

    After years of doing UI development using Motif, then MFC and finally Swing and WinForms, I've ended up doing some web UI development for the past few years, mainly for business apps. It's simple enough to do, but I spend far too much of my time thinking "What the fuck?!?!" when using libraries like jQuery or YUI.

    It's pretty bad that UI programming using C, C++, Java and even VB.NET was more enjoyable and productive than using JavaScript and jQuery.

    With web UIs, we end up spending a whole lot of time getting around browser-specific problems, and many times it's just really awkward to bend our UI to the HTML or AJAX model. Often times, things that would have been really quick to do with Motif or even MFC ended up taking much longer to develop using HTML, JavaScript and jQuery.

    And the UIs don't even look that good, too. We thankfully have some pretty good graphics designers working for us, and our web apps don't look bad, but they also don't look or feel as robust as native (or even pseudo-native like Swing) apps. Some of our users tell us that they found the old Motif apps easier to work with.

    I really don't like the direction the craft is heading. We were making good progress up until Swing and WinForms, but then web development took over and it feels like we've made a serious regression. So I'm thinking about moving away from UI design and development, after 20+ years. There are other areas where they're going in the right direction. Unless I can find myself a job using Qt somewhere. That's the only toolkit that seems to be making sensible innovation these days.

    • by slim ( 1652 ) <{john} {at} {hartnup.net}> on Monday January 11, 2010 @11:41AM (#30724388) Homepage

      The thing is, these are for writing slick Web pages, not desktop-like apps.

      If you want to write web apps that look like desktop apps, and feel like desktop apps to write, try GWT [google.com] or Cappuccino [cappuccino.org].

    • Re: (Score:2, Informative)

      by umghhh ( 965931 )
      You do not have to put much effort in convincing me that JS is source of all evil including Osama and rectal cancer but my observation over years brought me is understanding that the real pain that starts when somebody wants to use different language/set of tools over legacy code is caused not that much by the fact the legacy is coded in X but that legacy is coded badly in X. X is sometimes relevant but usually not significantly.
    • by rycamor ( 194164 )

      I really don't like the direction the craft is heading. We were making good progress up until Swing and WinForms, but then web development took over and it feels like we've made a serious regression.

      HTML was never intended to be an application language, just a document presentation one. And rather than develop an additional language to embed real application elements, we've spent the past 10 years trying to turn a hammer into a screwdriver.

      Mozilla tried to present a workable solution in the form of XUL [mozilla.org], which actually gives web developers a real GUI toolkit to work with. The world pretty much ignored or misused it, sadly. (Although I have to admit early XUL implementation was pretty buggy and limited).

    • That's because the DOM sucks ass. Libraries like Prototype and JQuery can make the DOM suck slightly less ass, but unfortunately you're still getting some ass-suckage leaking though.

      Believe me, if you were doing GUI programming in C++ or C# and had to go through DOM it would suck just as much.

    • by reed ( 19777 )

      Check out Google Web Toolkit or Pyjamas.

  • object-oriented? (Score:4, Informative)

    by gandhi_2 ( 1108023 ) on Monday January 11, 2010 @11:35AM (#30724320) Homepage

    Because you don't make classes and instances of the classes, you just use object.property notation, Javascript is NOT object-oriented. It is object-based.

    • function Apple (type) {
          this.type = type;
          this.color = "red";
          this.getInfo = getAppleInfo;
      }

      var apple = new Apple('macintosh');

      What is not OO about this? Maybe there's no keyword for it, but I certainly made a new instance of a class here.

      (example from http://www.phpied.com/3-ways-to-define-a-javascript-class/)
      • Re: (Score:3, Interesting)

        by gandhi_2 ( 1108023 )

        That is a prototype.

        JavaScript uses prototypes instead of classes for inheritance. It is possible to simulate many class-based features with prototypes in JavaScript.

        You are mimicking some of the utility, but that's not OO. Go ahead and show me is-a, has-a, and as-a inheritance in Javascript.

        • You are mimicking some of the utility, but that's not OO. Go ahead and show me is-a, has-a, and as-a inheritance in Javascript.

          There's no such thing as "has-a inheritance" in any language. Public inheritance is a "is-a" relationship, by definition (Liskov Substitution Principle etc). Of course, there are other ways to model "is-a", and JavaScript has them.

          Also, what's "as-a inheritance"?

          Anyway, why do you even believe that inheritance is required for something to be considered OO?

          • A porche IS A car.
            You already know about this, obviously.

            A car HAS A carburetor.
            http://en.wikipedia.org/wiki/Has-a [wikipedia.org]

            The as-a is seldom used, but objects of one class can be used as-a object of another derived class if the parent supports it and the language supports it. For example... road tire and spare tire both inherit from tire, but one can inherit from the other (like siblings) and be used AS another, while overriding only say max_speed=45 for the spare.

            • I know what "has-a" is about. You haven't explained how it has anything to do with inheritance, though.

              The as-a is seldom used, but objects of one class can be used as-a object of another derived class if the parent supports it and the language supports it. For example... road tire and spare tire both inherit from tire, but one can inherit from the other (like siblings) and be used AS another, while overriding only say max_speed=45 for the spare.

              This seems to be a very stretched example to me. I have never seen anything like that in production code, that's for sure. I also haven't seen it mentioned in any OOP/OOD theory books, either. Looking in Google doesn't bring anything up either, while plenty of hits are available for "is-a" and "has-a". Can you provide any reference for it?

              Also, in your example, I don't see any special kind of relationship.

            • A car HAS A carburetor.
              http://en.wikipedia.org/wiki/Has-a [wikipedia.org]

              Has class-based OO education gotten so crazy that we end up doing this with class hierarchies rather than simple composition?

            • by mcvos ( 645701 )

              A porche IS A car.
              You already know about this, obviously.

              A car HAS A carburetor.
              http://en.wikipedia.org/wiki/Has-a [wikipedia.org]

              The as-a is seldom used, but objects of one class can be used as-a object of another derived class if the parent supports it and the language supports it. For example... road tire and spare tire both inherit from tire, but one can inherit from the other (like siblings) and be used AS another, while overriding only say max_speed=45 for the spare.

              This sounds exactly like the kind of thing Javascript can do. Better than many other OO languages.

              The other two (is-a and has-a (which has nothing to do with inheritance, other than that subclasses inherit the property)) are obviously supported by Javascript.

        • Why not? (Score:3, Interesting)

          by weston ( 16146 )

          but that's not OO.

          Why not? Data structures married to methods which operate on them, information hiding, data abstraction, encapsulation, modularity, inheritance, polymorphism.... if you can do all these things, why get hung up on whether this is focused around defining classes or deriving from other objects and functions?

          Go ahead and show me is-a, has-a, and as-a inheritance in Javascript.

          Maybe if you explain the class-based analogue (it's not apparent what you mean by "has-a," and near as I can tell "is-

        • by toriver ( 11308 )

          Isn't that like saying that C++ is not object-oriented because classes are just fancy structs and methods are (pointers to) name-mangled top-level C functions?

      • Re: (Score:3, Insightful)

        by TheRaven64 ( 641858 )
        It is OO, but you did not make a new instance of a class, you made a new object. Apple is not a class, it is a closure. The semantics of the new keyword in JavaScript are the second most horrendous part of the spec. You're basically calling the closure with this bound to a new object which has Object as its prototype. A class is an object which is both a factory and a prototype. Here you have a factory, but not a prototype.
        • It is OO, but you did not make a new instance of a class, you made a new object. Apple is not a class, it is a closure.

          I'm trying to stretch the definition of a closure [wikipedia.org] to fit your statement and am not coming up with anything promising. I suppose you can look at an object as a scope of sorts and this or with as invoking that scope in the right context, but it doesn't seem to fit cleanly in my mind.

          The semantics of the new keyword in JavaScript are the second most horrendous part of the spec.

          It does what it

        • by mcvos ( 645701 )

          It is OO, but you did not make a new instance of a class, you made a new object.

          How is that not the same thing? Where are instances not objects?

          • Instances are objects, but objects are not all instances. Instances are created from a class. The class defines a (static) template for the object, which may (depending on the language) be amended later. In Self-like languages, including JavaScript, there are no classes so there is nothing to instantiate. The primitive operation is clone, not instantiate. When you create an object in JavaScript, rather than instantiating a class, you create copy of Object and then call a closure (which, confusingly, Ja
      • Re: (Score:3, Informative)

        by fm6 ( 162816 )

        You created an object that was predefined in the JS library. You can do that in any language. (Example: ActiveX objects in C programs.) JS is a little more advanced in that its syntax supports object manipulation. But if you can't define new classes, you can't build object frameworks. Definitely not OO.

        • But if you can't define new classes, you can't build object frameworks.

          I believe you mean:

          "if you can't define new classes, you can't build class hierarchies."

          But there's ways of doing things when it comes to frameworks beyond setting up a class hierarchy.

          Definitely not OO.

          Even if you start with the axiom that OO means classes (a questionable assertion at best), and even if you don't like manually dealing with the prototype hierarchy as a proxy, it's been pretty convincingly demonstrated that you build clas

          • by fm6 ( 162816 )

            But there's ways of doing things when it comes to frameworks beyond setting up a class hierarchy.

            In general yes. But please notice that I said "object framework" not "framework". And yes, class hierarchies are what you build with the ability to create new classes. Funny thing, though, object frameworks tend to be class hierarchies...

            Even if you start with the axiom that OO means classes (a questionable assertion at best)

            . Excuse me, you seem to be using OO as shorthand for both OOL and OOP, as if the two concepts were interchangeable. They're not.

            From the way you poo-poo classes, I'm also guessing that you're a fan of "duck" objects — that is, if it walks like an object, etc., it's a

            • From the way you poo-poo classes

              I'm not pooh-poohing classes in general; I'm happy to use classes and class hierarchies when they seem to fit the problem domain. The pooh-poohing I'm doing is the idea that you're not doing "real" object-oriented programming -- or that a language isn't an OOL -- if you don't have them built into the language.

              you seem to be using OO as shorthand for both OOL and OOP, as if the two concepts were interchangeable. They're not.

              I'm aware of the difference, having done OOP in even

              • by fm6 ( 162816 )

                The pooh-poohing I'm doing is the idea that you're not doing "real" object-oriented programming -- or that a language isn't an OOL -- if you don't have them built into the language.

                So any language that can implement objects is an OOL? So C is an OOL? Assembly language?

                • So any language that can implement objects is an OOL? So C is an OOL?

                  To quote my earlier post:

                  "having done OOP in even plain ol' C (definitely not the most OOL..."

                  So, no. I don't think of C as a particularly OOL. Perhaps minimally so because it provides a decent basis to get as OO as you like, but only minimally because it doesn't give you shortcuts for doing the three essentials we've discussed.

                  Javascript has convenient ways of doing all three built into the language, though, as I believe I've con

                  • by fm6 ( 162816 )

                    In other words, all languages are OOLs. In order to wedge JS into the category, you've made it meaningless.

                    • by weston ( 16146 )

                      In other words, all languages are OOLs.

                      No, I'd say at a minimum you need function pointers (or functions as a first class data type) and a mechanism for aggregate data types that can encompass them. Otherwise you can't really marry the methods to the members and abstracted mechanisms for inheritance and polymorphism probably aren't possible.

                      In order to wedge JS into the category, you've made it meaningless.

                      If there's any wedging being done in our discussion, it's on C, which might need it.

                      Javascript? It's g

                    • by fm6 ( 162816 )

                      Javascript? It's got objects and does encapsulation, polymorphism, and inheritance right out of the box.

                      The language doesn't do these things. The programmer does these things. It may be easier to work abroad the absence of these features in JS than in some other languages. That's just not the same thing as having the syntax and semantics built into the language.

                      You know, I can think of ways to do OOP in languages that don't support function pointers. It would be an evil kludge, but a Java programmer would say the same about your workarounds.

                    • by weston ( 16146 )

                      The language doesn't do these things.

                      Not at all. The language is doing the work when you type "Square.prototype = new Shape" in exactly the same way that the language is doing the work when you type "class Square extends Shape."

                      can think of ways to do OOP in languages that don't support function pointers.

                      I can too. However, off the top of my head I can't think of a way to build a library that abstracts away the manual/bookkeeping work involved in doing inheritance and polymorphism without them.

                      a Java prog

                    • by fm6 ( 162816 )

                      I love the way you cherry-pick your evidence and ignore the evidence already discussed. If you wanted to have an honest argument, you would have picked nits with my claim that (for example) encapsulation is done by the programmer, not the language. Instead you point to the ability to create objects.

                      That ability is in any language. That's the fourth time I've pointed it out, which is why this thread no longer has any interest for me.

    • You can write classes (which contain properties and methods) and then instance new objects from those classes with JavaScript. How is that not Object Oriented?
    • JavaScript is object oriented. In fact, it is a pure object-oriented language: everything is an object (even functions). It is not, however, a class-based language. Or are you going to claim that Self isn't an object oriented language either?
    • No language is object-oriented.

      Some programs are.

      You can write an object-oriented program in practically any language.

      Some kind of runtime code dispatching tool (like defgeneric, function pointers, or first-class function objects) is helpful.

  • Reading worth (Score:4, Interesting)

    by Rikiji7 ( 1182159 ) on Monday January 11, 2010 @11:36AM (#30724328) Homepage
    Thanks to jQuery javascript just makes sense. You can refer to and interact with things around the pages so easily that you will laugh thinking about the old days, when scripters were getting mad to write cross-browser js... Book is good and easy to read-through in a single day for an already experienced jscripter.
  • I am unable to find comparisons of JQuery and MooTools.

    If anyone has experience with both frameworks, could you please try to summarize the big differences and say which one you prefer?

    • I like jQuery more because... um... well, actually, I just like it more. Feels easier to use. MooTools has a steeper learning curve, and I can do what I want to in jQuery without that learning curve.

      Incidentally, although it is highly dependent on the browswer running the test, jQuery often feels faster. But run the tests [jquery.com] yourself. And while speed is one thing, accuracy is another, and it all depends on what kind of work you do.

      It gets really irritating, though, when I see a web site using both MooToo

    • Re: (Score:3, Insightful)

      by Mr. DOS ( 1276020 )

      I don't have any recent experience with MooTools, but when I was at a jQuery/MooTools crossroads about a year and a half ago, I chose jQuery for two reasons:

      • JS written using jQuery was more concise and easier to read/write
      • jQuery's documentation was better (at the time, I seem to remember large chunks of MooTools documentation missing; possibly because they'd just released a new version or something, but still bad)

      And that's about it. jQuery has given me no reason to look elsewhere; it's still concise and ea

Don't get suckered in by the comments -- they can be terribly misleading. Debug only code. -- Dave Storer

Working...