Slashdot Mirror


Learning JQuery 1.3

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.

153 comments

  1. Wow by El+Lobo · · Score: 3, Funny

    Key, then, to learning JQuery this book is.

    --
    It's time to realise that Abble's products are the biggest abomination these days. Just say NO to the dumb iAbble way!!
    1. Re:Wow by Tablizer · · Score: 1

      Key, then, to learning JQuery this book is.

      Dig new Yoda Series of books one must.
         

    2. Re:Wow by emurphy42 · · Score: 1

      He's riffing on this.

  2. HTML forms by Anonymous Coward · · Score: 2, Insightful

    Client side form handling is the browsers job.

    Roll on HTML 5

    1. Re:HTML forms by toastar · · Score: 2, Funny

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

    2. Re:HTML forms by Anonymous Coward · · Score: 0

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

      Flash, yes. Javascript, no.

      If you thought HTML5 was going to get rid of Javascript then you've completely missed the point. Javscript use is going to increase with HTML5, not decrease. HTML5 adds new objects and events to the DOM (eg sessionstorage), and the only way to make use of those is through Javascript.

      Sorry to disappoint you.

    3. Re:HTML forms by Tablizer · · Score: 3, Insightful

      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.
             

    4. Re:HTML forms by reed · · Score: 1

      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's Canvas is also more literally a blank slate... so will be interesting to see what happens with that.)

    5. Re:HTML forms by Anonymous Coward · · Score: 0

      In my opinion, we need a new kind of browser that is designed to handle desktop/CRUD GUI's well from the get-go.

      Isn't that what Flash is for?

    6. Re:HTML forms by dave420 · · Score: 1

      Or Flash, using ExternalInterface...

    7. Re:HTML forms by Tablizer · · Score: 1

      Isn't that what Flash is for?

      Kind of, but it's proprietary and is largely not based on a mark-up language. I think a mark-up language is the most palatable approach for cross-platform.

      I've been drafting up what I think it should look like on the C2 wiki in order to kick around the trade-off combos. It attempts what I think is a nifty design that allows one to nest and swap between MDI, tabbed, and "stacked list" groupings of sub-windows and/or sub-options. Each of these 3 are just different (potential) views of the same thing. Even the new "ribbon menu" style is just a fixed-position tabbed interface panel. Most desktop GUI's can be pretty much "reduced" to nested combo's of these 3 plus optional fixed-sized top, bottom, and/or side panels as containers. I've spent a fair amount of time trying to extract the "essential" building blocks of the majority of GUI's (excluding specific widgets, which could be handled as add-ons/plug-ins). I believe I've just about nailed it, or at least have yet to encounter significant exceptions. However, implementation is the detail devil I put off. I does ramble.
         

    8. Re:HTML forms by Anonymous Coward · · Score: 0

      You are describing Adobe FLEX! XML mark ups for GUI(they call it MXML), which gets compiled into Actionscript when you publish. AFAIK, the base classes only need to be downloaded once, and it can be cached and used by other FLEX swfs.

    9. Re:HTML forms by Rysc · · Score: 1

      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.

      --
      I want my Cowboyneal
  3. Functional programming by Camel+Pilot · · Score: 2, Interesting

    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.

    1. Re:Functional programming by ByOhTek · · Score: 4, Informative

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

      --
      Self proclaimed typo king, and inventor of the bear destroying coffee table (patent not pending).
    2. Re:Functional programming by Anonymous Coward · · Score: 0

      Please don't think that just using anonymous functions is functional programming. JavaScript is not a functional language.

      Functional programming is far more than that. Referential transparency, for instance, is a significant feature that is totally absent from JavaScript. You can't even declare constants in real-world JavaScript yet. Even then, if you use the DOM or any existing JavaScript libraries, you're basically stuck maintaining and manipulating state (which just isn't done when using a functional language).

      Most functional languages also offer strict, static typing, with type inference. This is something else that is completely contrary to how JavaScript works.

      Don't let JavaScript's poor attempts to include functional techniques taint real functional programming languages like Haskell, SML and OCaml for you. JavaScript is to functional programming as somebody sticking a crowbar up your ass is to a comforting back massage.

    3. Re:Functional programming by CobaltBlueDW · · Score: 0, Offtopic

      In JavaScript, easier said than trolled.

    4. Re:Functional programming by rob_osx · · Score: 3, Insightful

      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.

    5. Re:Functional programming by Stooshie · · Score: 1

      Anonymous functions. Eww!

      Don't, just don't!

      --
      America, Home of the Brave. ... .and the Squaw.
    6. Re:Functional programming by CaptSaltyJack · · Score: 1

      Dudes. Then get a real editor that handles auto-indentation. "Highly indented code" is a GOOD thing, I've worked with enough developers who slack on their indentation, and it makes the code a bitch to read.

    7. Re:Functional programming by Nadaka · · Score: 2, Insightful

      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"

    8. Re:Functional programming by slim · · Score: 3, Informative

      aka closures. If the language supports them, anonymous functions can be elegant and readable.

      To double every item in a Groovy list:

      mySet.collect { it * 2 }

    9. Re:Functional programming by Tablizer · · Score: 3, Insightful

      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.

    10. Re:Functional programming by slim · · Score: 3, Insightful

      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.

    11. Re:Functional programming by nschubach · · Score: 4, Informative

      Instead of:
      $(".someClass").each(
         function(index, element){
            somestuff();
         }
      );

      Do:
      function doThings(index, element){
         somestuff();
      }
      $(".someClass").each(doThings);

      --
      Every time I start to have faith in humanity, I ruin it by driving to work between 7 and 8 am.
    12. Re:Functional programming by slim · · Score: 1

      Proper indentation is of course essential.

      But "highly indented code", i.e. running out of space on the right, often means you're trying to do too much in one routine. Linus once stated that if you had trouble sticking to the 80 column, 8 char indent kernel coding style rules, you should be breaking your code into more functions.

      However certain styles of JavaScript programming (and Java, with anonymous inner classes) cause you to open a lot of brackets -- and therefore indent a long way -- for otherwise quite terse statements. That's what the GP was getting at.

    13. Re:Functional programming by Nadaka · · Score: 2, Informative

      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.

    14. Re:Functional programming by shutdown+-p+now · · Score: 1

      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.

    15. Re:Functional programming by rob_osx · · Score: 1
      Nadaka - I was incorrectly referencing procedural programming.

      Slim - thank you for trying to clarify my muddled post. You are totally correct that people use anonymous functions when a named function would be clearer.

      I blame my clouded mind on lack of sleep that comes from a 13 week old daughter. :-)

    16. Re:Functional programming by BlueBoxSW.com · · Score: 1

      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.

    17. Re:Functional programming by Anonymous Coward · · Score: 0
      Let's try a little experiment. Pick your favorite functional language, one that uses stateless atomic functions exclusively or whatever other criteria float your boat.

      Got it? Good.

      Is it turing complete? Does a turing machine satisfy your definition of functional?

    18. Re:Functional programming by ahem · · Score: 3, Funny

      ... Some if it is also subjective. We all think different. ...

      Actually, some of us think differently. Thanks a lot, Apple.

      --
      Not A Sig
    19. Re:Functional programming by izzev · · Score: 1

      jQuery is just massage oil

    20. Re:Functional programming by ByOhTek · · Score: 1

      Yes, that's why I trivially do it all over the place when I'm using that library.

      it's more readable, and creating a named function isn't much more difficult than creating an anon function... Unless you have difficulty coming up with function names, in which case, I'd say try to be descriptive rather than creative.

      --
      Self proclaimed typo king, and inventor of the bear destroying coffee table (patent not pending).
    21. Re:Functional programming by Tablizer · · Score: 1

      I've got a headache trying to figure out if "ly" suffix makes a difference. Thanks a lot, dude ;-)

    22. Re:Functional programming by Camel+Pilot · · Score: 1

      I am new to Javascript.

      However whenever I attempt to use named functions as shown... aka

      $(document).ready( function() {

          function doThings(index, element){ alert(index); }

        $(".test").each(doThings);

      });

      The function doThings() executes on compile.

    23. Re:Functional programming by khaledh · · Score: 1

      If you avoid using anonymous functions you sacrifice the power of closures.

    24. Re:Functional programming by TarMil · · Score: 1

      In languages as verbose as JavaScript, indeed, too many anonymous functions are evil. But when it's more elegantly made as in Haskell or ML-based languages, use them again and again.

    25. Re:Functional programming by Rysc · · Score: 1

      It may be more readable but it's a lot more verbose, meaning more typing and less code on the screen at once. Both of these things can be worse than losing a little descriptiveness.

      It is better to split out into named functions in some cases, but not every time (and often not for short bits of code). Maybe it's the Perl hacker in me talking, but sometimes the "less readable" version is easier to understand.

      --
      I want my Cowboyneal
  4. JQuery by Reality+Master+101 · · Score: 2, 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.

    --
    Sometimes it's best to just let stupid people be stupid.
    1. Re:JQuery by royallthefourth · · Score: 4, Insightful

      It's only 19kb and that tiny transfer only happens once because of browser caching. It's not too big for anything.

    2. Re:JQuery by Reality+Master+101 · · Score: 1

      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 the world.

      And you can run into problems with caching if you're using https.

      --
      Sometimes it's best to just let stupid people be stupid.
    3. Re:JQuery by Anonymusing · · Score: 0

      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.

      How big was the calendar pop-up you finally programmed yourself? And, could it do everything the pre-fab jQuery one could do?

      It's hard to complain that free code on the Internet is too big for your purposes. It's free. If you don't like it, roll your own.

      --
      Liberal? Conservative? Compare perspectives at Left-Right
    4. Re:JQuery by Azureflare · · Score: 1

      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 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).

    5. Re:JQuery by Azureflare · · Score: 1

      Eh, here's a link to the main page, that link that I gave was for the demo only: http://www.frequency-decoder.com/2009/02/03/unobtrusive-date-picker-widget-v4

    6. Re:JQuery by redJag · · Score: 1

      I believe you're talking about the jQuery UI Datepicker, whereas the 19kb is referring to just the jQuery library. jQuery UI can get pretty heavy, but you can use jQuery itself to write your own light-weight Calendar popup as well.

    7. Re:JQuery by Reality+Master+101 · · Score: 1

      How big was the calendar pop-up you finally programmed yourself? And, could it do everything the pre-fab jQuery one could do?

      I didn't program it myself, I used one the numerous ones available around the web. I think it was like 8K or something. And no, it didn't have all the animation gimmicks the JQuery one did, but it did what I needed it do -- er, popup a calendar, and input a date in a functional, attractive way.

      It's hard to complain that free code on the Internet is too big for your purposes. It's free. If you don't like it, roll your own.

      Sheesh, retract the geek rage. All I did was point out that it's really heavy if all you want is a simple control, and it is. It's useful information for someone who is considering JQuery, whose web site claims that it's super light weight. You know, offering the benefit of my experience using this newfangled "forum thing."

      And, if you note, since I didn't like it, I did "roll my own", as you suggested.

      --
      Sometimes it's best to just let stupid people be stupid.
    8. Re:JQuery by Mr.+DOS · · Score: 3, Informative

      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

    9. Re:JQuery by Reality+Master+101 · · Score: 1

      It's really cool, but the packed version + CSS file = 54K... Ouch. But I'm pretty obsessive about keeping web pages light and fast loading.

      --
      Sometimes it's best to just let stupid people be stupid.
    10. Re:JQuery by Lunix+Nutcase · · Score: 1

      the sum of all the various components was pushing 70-80K (yes, using the compressed versions).

      Which takes all of .16 seconds on even a low-end 512k DSL/Cable connection. Even on dialup that's not even 2 seconds (but one would question why one would be going to a javascript heavy website on dialup).

    11. Re:JQuery by clampolo · · Score: 1

      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.

    12. Re:JQuery by greenreaper · · Score: 1

      No it doesn't. Even without the possibility of collisions, TCP takes time to ramp up. Still, you can normally put the download at the end of the page and it won't matter.

    13. Re:JQuery by Reality+Master+101 · · Score: 2, Insightful

      Which takes all of .16 seconds on even a low-end 512k DSL/Cable connection. Even on dialup that's not even 2 seconds (but one would question why one would be going to a javascript heavy website on dialup).

      Okay, first of all, that "512k" connection is 512 kilo-BITS. That means 64 kilo-BYTES / second. So that 80K download takes an extra one and a quarter seconds. That may not sound like much, but it adds up.

      And if the whole world was broadband, then I'd be less concerned, but a lot of the world is still on crappy dial-up connections. A typical dial-up connection is 33 Kbits or about 4K Bytes/second. That means that 80K download is 20 seconds. 20 seconds NOT EVEN RELATED TO CONTENT. Try counting off 20 seconds and see how long that really is.

      I don't know about anyone else, but I want my web pages to pop. Snap! Snap! Snap! I HATE waiting for crappy designed web pages to load, and I'm on a 16 megabit connection.

      --
      Sometimes it's best to just let stupid people be stupid.
    14. Re:JQuery by Anonymusing · · Score: 1

      Sheesh, retract the geek rage. All I did was point out that it's really heavy if all you want is a simple control, and it is.

      No rage here. It seemed like you were complaining about something unnecessarily, and I meant my comment matter-of-factly. My apologies if it came across too strongly.

      --
      Liberal? Conservative? Compare perspectives at Left-Right
    15. Re:JQuery by stdarg · · Score: 1

      I just made my first project with jquery and I used a publicly hosted copy of the library: http://code.google.com/apis/ajaxlibs/documentation/index.html#jquery

      The goal of course is to have a bunch of sites point to this shared copy (including popular ones like google) and then rely on browser caching to offset the cost of the download.

    16. Re:JQuery by GigaHurtsMyRobot · · Score: 1

      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 delimited text would prove sufficient. I've re-written them from scratch and proven it.

    17. Re:JQuery by daveime · · Score: 1

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

    18. Re:JQuery by Anonymous Coward · · Score: 0

      If you still want to use JQuery you could use the Google CDN.
      http://encosia.com/2008/12/10/3-reasons-why-you-should-let-google-host-jquery-for-you/

    19. Re:JQuery by Wraithlyn · · Score: 1

      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 provide "packed" (compressed) versions which were smaller (last one clocked in at ~30KB), but these were never a good idea to use (which is why they were discontinued) as they had to be decompressed by the browser on *every* page load, whereas the larger size of the minified version is a one-time penalty due to browser cache.

      --
      "Mind, as manifested by the capacity to make choices, is to some extent present in every electron." -Freeman Dyson
    20. Re:JQuery by Ungrounded+Lightning · · Score: 1

      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).

      --
      Bantam Dominique roosters crow a four-note song. Once you've heard it as "Happy BIRTHday" you can't NOT hear it that way
    21. Re:JQuery by Ungrounded+Lightning · · Score: 1

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

      --
      Bantam Dominique roosters crow a four-note song. Once you've heard it as "Happy BIRTHday" you can't NOT hear it that way
    22. Re:JQuery by Seakip18 · · Score: 1

      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.

      --
      import system.cool.Sig;
    23. Re:JQuery by Mr.+DOS · · Score: 1

      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. DOS

    24. Re:JQuery by Mr.+DOS · · Score: 1

      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

    25. Re:JQuery by David+E.+Smith · · Score: 1

      Never underestimate the patience of the dial-up user. My mother refuses to move past dial-up (mostly because I've got her a free account, whereas she'd have to pay a whoppin' ten bucks a month for DSL), and does in fact watch YouTube videos. Yes, it takes two or three hours for the video to download, but it can be done apparently.

      Next to that, an extra few seconds for jQuery is nothin'.

    26. Re:JQuery by Anonymous Coward · · Score: 0

      Most people link to Google's hosted minified code. Google uses gzip, and since everyone links to this same file it is probably already cached on your browser.

    27. Re:JQuery by Anonymous Coward · · Score: 0

      Tell me, do you keep your signature in a convenient clipboard buffer, or do you retype it with every post? Regardless, you are pathetic.

    28. Re:JQuery by mcvos · · Score: 1

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

    29. Re:JQuery by Rysc · · Score: 1

      I didn't program it myself, I used one the numerous ones available around the web. I think it was like 8K or something. And no, it didn't have all the animation gimmicks the JQuery one did, but it did what I needed it do -- er, popup a calendar, and input a date in a functional, attractive way.

      A few extra kb is a small price to pay for having a well tested and robust calendar, IMO. Being hard to break and not having bugs are both important to me. And, once I've loaded the 80k or whatever anyway, I find it's seductively easy to sprinkle little bits of jQuery here and there to great effect.

      Most pure JS calendar code out there is really horrible, really incomplete or both. jQuery's animations and whatnot don't add a huge overhead in the codebase and you can (and should) turn them off.

      --
      I want my Cowboyneal
  5. What has UI development become? by Anonymous Coward · · Score: 4, Insightful

    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.

    1. Re:What has UI development become? by slim · · Score: 3, Informative

      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 or Cappuccino.

    2. Re:What has UI development become? by umghhh · · Score: 1, Informative

      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.

    3. Re:What has UI development become? by rycamor · · Score: 1

      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, 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). At present, XUL is mainly used to create Firefox extensions, but even there we see a movement away from that to HTML.

      Be that as it may, you have to admit that there are things web apps deliver that the traditional client-side program couldn't. Will we ever see a good marriage of the two? I suppose it's possible, but for the near future I foresee more and more of this 'papering over'; layering frameworks on top of suboptimal core technology in order for developers to at least achieve some sanity.

    4. Re:What has UI development become? by Blakey+Rat · · Score: 1

      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.

    5. Re:What has UI development become? by reed · · Score: 1

      Check out Google Web Toolkit or Pyjamas.

    6. Re:What has UI development become? by happy_mart · · Score: 1

      Having used GWT for the whole past year, I can ensure you that using it does not totally feel like writing desktop apps. You definitely still have to understand very well how the DOM and css properties are working to obtain nicely looking and mainly, nicely resizing pages. Furthermore, since, in the browser, you do not have direct storage available, you are relying very much on asynchronous calls to a server to obtain any kind of persistency, which makes theh process very differnet than writing to files. That said, I must point that manipulating complex data structures is really easier using java compiled to javascript than directly using javascript (if only for the debugging facilities offered by GWT). My point is : GWT definitely helps you write slick web app looking like destop app, but the abstraction remains very leaky.

    7. Re:What has UI development become? by crh3675 · · Score: 1

      Well, there is no silver bullet towards building web sites and even web apps. Problem is always about proper and cohesive implementation. With ridiculous turnaround times for many clients, jQuery makes it less painful to implement solutions. I really don't spend anytime integrating jQuery solutions that create or have cross-browser issues. Those issues are mostly with CSS and XHTML layout and not a problem with the library. I enjoy working with jQuery and I create useful UI solutions with it. Is it the best library to work with? Not sure but I use it very well to find practical solutions for my UI needs. It sounds like your perspective is that of a programmer that wants little to do with handling the UI and I can fully understand that mindset. Which makes even more sense to have a UI specialist in jQuery or the latter to implement the best solutions for the frontend.

  6. object-oriented? by gandhi_2 · · Score: 3, Informative

    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.

    1. Re:object-oriented? by royallthefourth · · Score: 1

      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/)

    2. Re:object-oriented? by Fahrvergnuugen · · Score: 1

      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?

      --
      Kiteboarding Gear Mention slashdot and get 10% off!
    3. Re:object-oriented? by gandhi_2 · · Score: 2, Interesting

      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.

    4. Re:object-oriented? by Anonymous Coward · · Score: 0

      Wrong again. JavaScript is an object-oriented, prototype-based (instead of class-based) language.

    5. Re:object-oriented? by Anonymous Coward · · Score: 0

      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.

      Just because JS doesn't call them "classes", doesn't mean they're not. You do define classes, and you do create instances of those classes. You can even use inheritance. It's not the nicest OO language out there, but it is OO.

    6. Re:object-oriented? by TheRaven64 · · Score: 1

      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?

      --
      I am TheRaven on Soylent News
    7. Re:object-oriented? by Anonymous Coward · · Score: 0

      Tosh. Javascript, like Self, just doesn't use inheritance. You can fundamentally create generic or base objects, including giving them object-oriented methods which can access an implicit 'this' for self-reference, and then instances of those using the 'new' keyword.

      These objects are defined without inheritance, instead using a constructor that sets the object's 'prototype': a live instance of an object that has all of the fundamental properties of the newly defined object, which can be overridden by the instance. Furthermore, those prototype objects can themselves be the product of constructors, and have their own prototypes, all the way down to Object/Array. This is simply implicit rather than explicit inheritance.

      See: http://en.wikipedia.org/wiki/Prototype-based_programming

      It's outdated nonsense to put prototype-based languages in the old-fashioned 'object-based' category that was contrived around limited languages like Visual Basic; Javascript and Self both clearly meet the fundamental requirements of object-oriented programming, and if they don't then it is the definition that needs to change.

    8. Re:object-oriented? by QuoteMstr · · Score: 1

      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.

    9. Re:object-oriented? by Tablizer · · Score: 1

      Prototyping is a form of inheritance. In fact, it could be argued that wetware (biology) uses prototyping for inheritance such that prototyping is closer to the original concept of "inheritance" than class-based. No biologist has discovered the master "primate class" (please, no jokes about monkeys flinging poo at teachers).

           

    10. Re:object-oriented? by CobaltBlueDW · · Score: 1

      Making Objects and Orienting a language to Objects are quite different.

      JavaScript uses what is called Prototyping, which is arguably the bastard step sibling of a proper class system.

      Many of the powerful features inherent to classical class based system are hard to produce with JavaScript's prototyping system, which has it's own flaccid pros, but arguably quite inferior to a strong class based system.

    11. Re:object-oriented? by gandhi_2 · · Score: 1

      You could argue that the spirit is the base class, although it is pure virtual.

    12. Re:object-oriented? by TheRaven64 · · Score: 2, Insightful

      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.

      --
      I am TheRaven on Soylent News
    13. Re:object-oriented? by Anonymous Coward · · Score: 1, Informative

      Again you're assuming that is-a, has-a and as-a are necessary components of OO development. They are merely necessary components of class/inheritance-based OO development.

    14. Re:object-oriented? by shutdown+-p+now · · Score: 1

      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?

    15. Re:object-oriented? by Anonymous Coward · · Score: 0

      From Wikipedia (http://en.wikipedia.org/wiki/JavaScript):

      "JavaScript is an object-oriented scripting language used to enable programmatic access to objects within both the client application and other applications."

    16. Re:object-oriented? by The+End+Of+Days · · Score: 1

      JavaScript is one of those things that is hated and misunderstood in equal measure, mostly by the same people. I think a lot of it is the inherent prejudice techies seem to have against providing UI. I couldn't tell you how many times I've listened to rants about how UI work is easy and boring, nothing to it, blah, blah, blah, by people who couldn't do the work to save their lives.

      Just another instance of the general principle that people tend to deride as easy that which they cannot actually do.

      In the end, I shrug. If a carpenter decides he has no need of a hammer, who am I to make fun of the nail marks on his screwdriver handle? The way I see it, that leaves more money for me to make.

    17. Re:object-oriented? by fm6 · · Score: 2, Informative

      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.

    18. Re:object-oriented? by tepples · · Score: 1

      JavaScript uses what is called Prototyping, which is arguably the bastard step sibling of a proper class system.

      You keep using that word.

      Many of the powerful features inherent to classical class based system are hard to produce with JavaScript's prototyping system

      Name a couple, please.

    19. Re:object-oriented? by gandhi_2 · · Score: 1

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

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

      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.

    20. Re:object-oriented? by losinggeneration · · Score: 1

      Javascript uses a form of OOP called prototype-based. Just because it's not class-based doesn't mean it's not OOP. Now please go ahead and look it up if you still have doubts. After a bit of reading it should become quite clear that you've been misinformed about what exactly is OOP.

    21. Re:object-oriented? by shutdown+-p+now · · Score: 1

      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. If we have Tire, RoadTire->Tire and SpareTire->Tire, then we just have two "is-a" relationships, and the fact that RoadTire and SpareTire can be used interchangeably where any Tire is expected is just the fundamental nature of "is-a". If we have SpareTire->RoadTire, or RoadTire->SparedTire, then we again have "is-a". If we don't have any inheritance relationship between the two, but we can pass a RoadTire to something expecting SpareTire, and vice versa, then it sounds like duck typing to me.

    22. Re:object-oriented? by shutdown+-p+now · · Score: 1

      I believe "private inheritance" allows for as-a relationships.

      Your second link sheds some light on this:

      "The relationship between a parent and child class under private inheritance is not "is a", but "is implemented as a"

      which is of course a very different thing. It doesn't have much to do with OOD, either, since "implemented as", is an implementation detail that isn't visible to class clients. Indeed, if we look at private inheritance in C++, it doesn't allow to substitute object, where an instance of parent class is expected, from outside that class. As such, it's not a kind of relationship that can be captured in a class or entity diagram (at best, it can be approximated with composition).

    23. Re:object-oriented? by toriver · · Score: 1

      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?

    24. Re:object-oriented? by Tablizer · · Score: 1

      SOP - Supernatural Oriented Programming? I'd like to see a language that implements re-incarnation.

    25. Re:object-oriented? by mcvos · · Score: 1

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

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

      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.

    26. Re:object-oriented? by mcvos · · Score: 1

      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?

    27. Re:object-oriented? by TheRaven64 · · Score: 1

      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, JavaScript calls functions) to initialize it, which may include changing its prototype.

      --
      I am TheRaven on Soylent News
    28. Re:object-oriented? by DragonWriter · · Score: 1

      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.

      Prototype-based object-oriented languages and class-based object-oriented langauges are both legitimately object-oriented; they are two different means of enabling object-oriented programming style. "Object-oriented" doesn't mean "class-based".

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

      Its trivial to implement class-like, is-a style relationships in JavaScript, though since it is a dynamic language, there's little need to; "has-a" relationships are delegation, not inheritance--and are implemented in JavaScript in pretty much the same way they are in popular class-based OO lnaguages. I'm not sure what you mean by "as-a" -- that sounds like casting, which is zero-effort in JavaScript.

    29. Re:object-oriented? by Tacvek · · Score: 1

      Private inheritance under C++ actually roughly resembles a has-a relationship.
      It is functionally rather similar to composition, except that the composed object has no name. There are some differences, especially with respect to calling virtual functions of the private base-class from within the derived class, but otherwise it is very similar to composition. This is probably why it is not seen very often.

      As for as-a inheritance, I have no idea. It almost sounds like a pattern in which one adds an adapter as a subclass to make the class conform to an interface it semantically supports, but does not syntactically support.

      --
      Stylish sheet to fix many problems in Slashdot's D3: https://gist.github.com/801524
  7. Reading worth by Rikiji7 · · Score: 4, Interesting

    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.

    --
    slashwhat?
  8. For cross browser compat by Anonymous Coward · · Score: 0

    Once IE10?...11 comes out and all browsers have a standard JavaScript implementation all of these JavaScript frameworks will be borderline obsolete.

    obj.addEventListener will be obj.addEventListener NOT
    if(obj.attachEvent){...}else if(obj.addEventListener){...}else{...}

    They will still have the convenience functions for Ajax, DragNDrop, and XPath, but once cross-browser annoyances are off the table the convenience factor becomes just another layer of abstraction.

  9. JQuery vs. MooTools by A+Friendly+Troll · · Score: 1

    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?

    1. Re:JQuery vs. MooTools by Anonymous Coward · · Score: 1, Interesting

      This is a good read. http://jqueryvsmootools.com/

      The author makes note that he personally prefers mootools, which has more of a learning curve, but makes sense.

      Also, I saw somewhere that mootools has better performance than jquery in benchmark tests of some kind.

    2. Re:JQuery vs. MooTools by Anonymusing · · Score: 1

      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 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 MooTools and jQuery on the same page, just because the designer/developer liked a particular plug-in for that page. I'm sure the client never notices.

      --
      Liberal? Conservative? Compare perspectives at Left-Right
    3. Re:JQuery vs. MooTools by A+Friendly+Troll · · Score: 1

      I found that site, but immediately discarded it when I read "I am a MooTools developer" in the disclaimer. I'd like to hear from people around here instead :)

    4. Re:JQuery vs. MooTools by Mr.+DOS · · Score: 2, Insightful

      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 easy-to-use, it's fairly fast, it's compatible with as many browsers as I'm willing to target for CSS, and there's a million and one plugins so often the only JS I need to write is that to enable a plugin.

            --- Mr. DOS

    5. Re:JQuery vs. MooTools by phloe · · Score: 1

      The author is very subjective considering his affiliation with mootools. Give it a read.

    6. Re:JQuery vs. MooTools by nschubach · · Score: 1

      Even I could argue that.   He takes an example ( http://jqueryvsmootools.com/#chaining ) from the tutorials explicitly on the use of end() and pretty much declares it a required form then shows a method to do the same thing in MooTools in a cleaner way (which can also be done in jQuery...):

      $(document).ready(function() {
         var faq = $('#faq');
         faq.find('dd').hide();
         faq.find('dt').click(function() {
            $(this).next().slideToggle();
         });
      });

      There's obvious bias in that "comparison."

      --
      Every time I start to have faith in humanity, I ruin it by driving to work between 7 and 8 am.
    7. Re:JQuery vs. MooTools by booch · · Score: 3, Informative

      As a jQuery user, I actually found that comparison by a MooTools developer to be pretty fair.

      --
      Software sucks. Open Source sucks less.
  10. Javascript by Anonymous Coward · · Score: 0

    Developers are using Javascript because they have no choice. Web development sucks, and Javascript is one of the reasons.

    1. Re:Javascript by MightyMartian · · Score: 2, Informative

      Amen! The browser is probably the worst application platform ever developed. It's a godawful mess only made worse by the different browsers and by having to support even worse legacy variants like IE6. I can only imagine if, 20 years ago, someone had come up and showed CSS and DHTML coupled together on top of a rendering engine using a terrible language like JavaScript as the glue, they would have looked at it, looked at MacOS and Windows, even in their relatively primitive forms, and laughed their asses off.

      --
      The world's burning. Moped Jesus spotted on I50. Details at 11.
    2. Re:Javascript by CobaltBlueDW · · Score: 1

      Agreed.

      HTML is a horrible way to depict graphical content, and wasn't made to.

      JavaScript is a terrible language, but how do you fix a language which everyone has already created their own implementation for, and which no one person has any control over.

      CSS is a mess built on top of a mess.

      Rigging them all together is like trying to create Frankenstein with jellyfish and hair-pins.

      Now if only we could get a object/vector-based graphics system hooked-up to a solid OO language, and give it a flashy name. ;)

      --but seriously, a vector graphics driven web browser running a good scripting language, or at least a popular scripting language like ActionScript3, Python, Ruby or c#, could create some brilliant results.

    3. Re:Javascript by Saint+Stephen · · Score: 1

      What I hate is the float:left and clear:both bullshit in CSS. That's got to be the dumbest, most non-intuitive thing I've ever seen. "Let me express this in the most bass-ackward way possible."

    4. Re:Javascript by tepples · · Score: 1

      Now if only we could get a object/vector-based graphics system hooked-up to a solid OO language, and give it a flashy name

      You mean "HTML5"? If you meant "flashy" as in Adobe, you'll run into one of the consequences of Flash Player being non-free: unless your device is a traditional PC, you have to pay Adobe if you want your device to be able to view "flashy" documents.

    5. Re:Javascript by MightyMartian · · Score: 1

      Nothing about CSS is intuitive. It has got to be the most gawdawful attribute system ever developed. You'd think these guys would be so ashamed, they'd slit their wrists or leap off of high buildings. Instead, they write books about how it, and these books are littered with "this is the really clever bit", as if what they were hawking had some semblance to what an intelligent developer could create.

      I fucking hate CSS, I hate browsers as application platforms. Even if every browser behaved exactly the same, it would still suck.

      --
      The world's burning. Moped Jesus spotted on I50. Details at 11.
  11. Ghastly cover by Tablizer · · Score: 1

    I have to say, that book cover reminds me of the day I had way too much pizza, and let's just say the pizza took upon itself to make a U-turn.
       

    1. Re:Ghastly cover by gregarican · · Score: 1

      I don't understand what you're trying to say. Can you please come up with an appropriate pizza analogy???

    2. Re:Ghastly cover by shutdown+-p+now · · Score: 1

      So, PizzaAnalogyGuy is your virtual, then?

    3. Re:Ghastly cover by Tablizer · · Score: 1

      One last time:

      1. Eat Pizza
      2. Stick Finger Down Throat
      3. Results Come Out
      4. Photograph Results
      5. Put Results on Book Cover
      6. Profit!

  12. JavaScript and jQuery are RELIGIONS. by Anonymous Coward · · Score: 0

    You have to understand, JavaScript isn't just a scripting language, and jQuery isn't just a library. They've basically become religions for some people, much more so than we've even seen for any other programming technology.

    I think it has to do with the advocates of those technologies not having any real programming skills or experience. Since they've never been good enough to program in Qt or Swing or even Visual Basic, they can't see all of the horrid flaws that are prevalent throughout JS and jQuery.

    Complete ignorance brings out the reaction that Anonymusing just subjected you to.

  13. We don't use JavaScript here we use JQuery by SpoodyGoon · · Score: 0

    We don't use JavaScript where I work we use JQuery instead it's a lot more intuitive.

    1. Re:We don't use JavaScript here we use JQuery by Megahard · · Score: 1

      Huh? That's like saying you don't drive you use a GPS.

      --
      I eat only the real part of complex carbohydrates.
    2. Re:We don't use JavaScript here we use JQuery by Anonymous Coward · · Score: 0

      Are you some kind of fucking retard?

    3. Re:We don't use JavaScript here we use JQuery by Anonymous Coward · · Score: 0

      More like a "SpoogyLoon", but this is Slashdot so that was already taken when he signed up.

  14. Excellent Timing by Supergibbs · · Score: 1

    JQuery 1.4 alpha 2 just came out and the final version is scheduled for Thursday.

    --
    First post! (just in case I am...)
  15. Why not? by weston · · Score: 2, Interesting

    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-a" and "as-a" are the same thing in a language where you can apply duck-typing). Bonus if you can point out a type of problem without classes.

  16. Since when is gzipping your output not available? by Anonymous Coward · · Score: 0

    Oh for pity sake. "This feature isn't always on or available?

    Two lines of php are sufficient to send a text/javascript and compress header, then a readfile of the pre-compressed jquery.js file, which you have prepared offline using the gzip command as a -c, will send the 11K file.

    So, to answer my question: gzipping output is not available if the client browser is 10 years old or older.The browser will not know the difference unless it is pre-Netscape 4.x.

    Also packer not jsminify.

    If you're really hard on yourself, use non-parsed headers and cgi to send and the script becomes two echoes and a cat command.

  17. Composition. No class relationship. by weston · · Score: 1

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

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

  18. Closures; type vs prototype by weston · · Score: 1

    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 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 says it does: creates a new object with a given prototype initialized with a constructor that's a function of the same name.

    You're basically calling the closure with this bound to a new object which has Object as its prototype.

    No, the type is object. The prototype is the "Apple" object (or, more precisely, the immediate link up the prototype chain is Apple and then ultimately Object).

  19. Frameworks vs Heirarchies; OO != Class by weston · · Score: 1

    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 classes onto standard javascript.

    1. Re:Frameworks vs Heirarchies; OO != Class by fm6 · · Score: 1

      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 an object. I'm not going to criticize the duck object paradigm, but it's definitely not the same as the OOP paradigm. To insist that "duck" and "classical" objects are the same is like insisting that anything that keeps you warm is fur.

      You can do OOP in any language (it's just a set of programming conventions after all) but it's a lot easier to do OOP in an OOL. And I was taught to be a real OOL, and not just a procedural language with pretensions, you have to support encapsulation (hiding the inner workings of the object from the code that uses it), polymorphism (the ability for various kinds of objects to all support the same method, so that user code doesn't need to know precisely what kind of object it's dealing with) and inheritance (the ability to define new object types based on an existing object types). All three of those criteria don't work without something resembling classes. If you think you can define "OOL" without reference to classes, by all means enlighten me.

      it's been pretty convincingly demonstrated that you build classes onto standard javascript.

      Link?

      Please note that I'm perfectly willing to be proven FoS. It's the only way you learn stuff.

  20. JQuery is for undisciplined programmers by Anonymous Coward · · Score: 0

    O'Reilly 2nd and 3rd editions of JavaScript explained everything you'd want to know about JavaScript but, like any other book on a language, didn't teach programming. JQuery might be convenient but it isn't likely to add value to properly written code. If you knew what you were doing with JavaScript in 1999 and maintained your library from that point forward, the only thing JQuery would add is the overhead of getting to know someone else's code.

    Maybe this book is different; maybe it really is documentation. That is, information for programmers without the self-righteous crap or the marketing nonsense inherent to the Perl books from that same publisher. The shoulders that need repair after all the self-praise must give sports medicine something to write about. (Sigh). If only David Flanagan would write a Perl book.

    Comparisons of JavaScript code with JQuery to code without JQuery -- and that omit consideration of the quality (or lack thereof) of the plain-old JavaScript -- shouldn't give JQuery any credibility. But they do, it seems. How ex- paste-up editors write code -- code from any programmer with little engineering prowess -- doesn't seem to be a basis for comparing any tool (sugar).

    As David Flanagan wrote on his blog: "Good algorithms are better than clever code".
    http://www.davidflanagan.com/2009/08/good-algorithms.html

    As long as the folks I work with insist on using it I'll be stuck with it -- since I didn't maintain my libraries after 2003. Good thing for JQuery that the best of the programmers I work with thinks highly of it. Maybe its just me -- he likes the Perl texts, too.

  21. Dojo? by gunners007 · · Score: 1

    Where does Dojo stand vis-a-vis jQuery?

  22. Web 'developers' GET OUT by Anonymous Coward · · Score: 0

    What the hell is this kind of shit doing on Slashdot? People who use toy languages like CSS and JQuery are not 'programmers' or 'developers', they're simpletons who aren't intelligent enough to program in REAL languages like C, Assembler and BASH scripts. As such they don't belong on this site, and nor do their Fisher-Price 'tools'.

  23. Non-class-based OO demonstrated! by weston · · Score: 1

    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 plain ol' C (definitely not the most OOL, but structs can hold function pointers and after that it's a matter of bookkeeping, which is why Strousup was able to more or less make the first implementation of C++ with a glorified C preprocessor). It's a good exercise which helps one appreciate the possibilities of a generally capable language as well as the work that other languages will do for you.

    I'm not going to criticize the duck object paradigm, but it's definitely not the same as the OOP paradigm.

    I suspect some confusion between static strong typing and classes. Some of the most dominant languages in the industry do things this way, which I think leads to the confusion, but it's only one possible mix of two largely orthogonal concerns.

    But let's get to the meat of my comment:

    And I was taught to be a real OOL, and not just a procedural language with pretensions, you have to support encapsulation (hiding the inner workings of the object from the code that uses it), polymorphism (the ability for various kinds of objects to all support the same method, so that user code doesn't need to know precisely what kind of object it's dealing with) and inheritance (the ability to define new object types based on an existing object types).

    Sounds like a pretty good list to me.

    All three of those criteria don't work without something resembling classes.

    Sigh. And we were on a roll there. Let's go back to talking about Encapsulation, Polymorphism, and Inheritance.

    Encapsulation: Javascript has methods, so it has OO encapsulation. That's my threshold, anyway. For some people it's different; they take the term to mean there exist means to ensure one can't examine the internal state of an object, that the language has some mechanism for enforcing privacy of member data. Personally, I think that many programmers overuse and abuse language-level enforcement mechanisms of this kind. If you're doing your design well, the methods you provide will be so convenient a developer won't even be curious about implementation and internal state. But there are some cases where enforcement really is important, and some people who aren't satisfied that it's OO if there's not a mechanism for it. So, in Javascript, you can do this with lexical scoping rules and closures:

    function Example() {
    var private = 0;
    this.get = function () { return private; }
    this.set = function (v) { private = v; }
    }

    e = new Example();
    e.set(5);
    e.private // the interpreter will have no idea what you're talking about, so it'll yield null
    e.get(); // yields 5

    You've got a simple object with a single private property that can be modified by a setter, retrieved with a getter, and touched no other way. And without being told or seeing the source, the programmer won't know whether Example objects do their storage in a closed-over scope, or on a remote server, or in a local database. Simple privacy-enforced encapsulation of concerns.

    Polymorphism: if an object has a method, it'll respond to it. If not, you'll get an error/exception.

    function Counter() {
    var i = 0;
    this.get = function () { return i++; }
    }

    function showObjValInTextBox(o) {

    1. Re:Non-class-based OO demonstrated! by fm6 · · Score: 1

      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?

  24. C? Maybe minimally so. Javascript? Certainly. by weston · · Score: 1

    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 conclusively shown.

    Assembly language?

    Possibly more purely than anything else, as it's nothing but method calls on a few simple real objects. ;)

    (Seriously, I'm happy to draw a bright line between 2GLs and 3GLs)

    1. Re:C? Maybe minimally so. Javascript? Certainly. by fm6 · · Score: 1

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

    2. Re:C? Maybe minimally so. Javascript? Certainly. by weston · · Score: 1

      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 got objects and does encapsulation, polymorphism, and inheritance right out of the box. I'm using your definition:

      to be a real OOL, and not just a procedural language with pretensions, you have to support encapsulation (hiding the inner workings of the object from the code that uses it), polymorphism (the ability for various kinds of objects to all support the same method, so that user code doesn't need to know precisely what kind of object it's dealing with) and inheritance (the ability to define new object types based on an existing object types)

    3. Re:C? Maybe minimally so. Javascript? Certainly. by fm6 · · Score: 1

      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.

    4. Re:C? Maybe minimally so. Javascript? Certainly. by weston · · Score: 1

      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 programmer would say the same about your workarounds.

      Which Java programmer? I'm a Java programmer, among other things, and I wouldn't say that at all.

      Perhaps you're talking about people who know chiefly Java and not much else?

    5. Re:C? Maybe minimally so. Javascript? Certainly. by fm6 · · Score: 1

      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.

    6. Re:C? Maybe minimally so. Javascript? Certainly. by weston · · Score: 1

      I love the way you cherry-pick your evidence and ignore the evidence already discussed.

      Feel free to list points that I've ignored.

      If you wanted to have an honest argument

      I've made one.

      you would have picked nits with my claim that (for example) encapsulation is done by the programmer, not the language.

      As I pointed out earlier, most of the time I believe encapsulation is a design issue, so, no, not really. But if you'd like, you can focus on my earlier statement that sometimes it's important to have a mechanism in the language for enforcing it, and I demonstrated that mechanism. One that I might add is as succinct and labor equivalent as comparable Java code, and relies on a feature woven as completely into the language as a "private" or "protected" keyword.

      Instead you point to the ability to create objects.

      Sure, among other things, including the ability to do all the things you layed out as general criteria for an OOL.

      That ability is in any language. That's the fourth time I've pointed it out

      You've made that claim, I've challenged you, and rather than explaining in detail, you've simply reiterated. Perhaps you need to watch the video in your sig, but I'd settle for an elaboration.

      which is why this thread no longer has any interest for me.

      It's a pity. You clearly have a lot left to learn.