This Week in jQuery, vol. 1

Posted on by

This is the first in what we’re hoping to be a weekly series of blog posts about what is going on in the world of jQuery. We’ll take a look at new or updated plugins, recent tutorials, and other jQuery-related news.

Book

Learning jQuery 1.3

Jonathan Chaffer and I (Karl Swedberg) just had our book Learning jQuery 1.3 published by Packt Publishing. It’s an update of the popular Learning jQuery book, which was released nearly two years ago. The new one features additions to the library (event namespacing, JSONP, new effects methods, etc.) introduced since the release of the first book, improved and extended examples, expanded plugins chapters, and a quick reference to all methods and selectors. It’s available on the Packt website and on amazon.com.

Magazine

JSMag, a promising new magazine for JavaScript developers, just published their first issue. The magazine’s goal is to provide “quality JavaScript content to educate, motivate and inspire you in your work with JavaScript.” PDF-only issues are US$4.99 each, with bulk licensing discounts starting at 30% off the individual price. Contents of the first issue include:

  • Debugging JavaScript without alert()
  • Introduction to ExtJS
  • Community News
  • Unit testing with YUI
  • What’s new in jQuery 1.3
  • Functional Programming in JavaScript

Check out a sample (PDF) from the first issue.

Plugins

Among the ever-growing selection of jQuery plugins, a few perennial favorites were updated this week. Ariel Flesler released version 1.2.7 of his LocalScroll plugin, which animates anchor navigation within a web page. Mika Tuupola updated his Jeditable plugin, for seamless in-place editing, with a number of “callback hooks” and a few bug fixes. Josh Bush’s new version of Masked Input includes bug fixes and a few feature enhancements as well.

After looking for a simple, fast and flexible grid/spreadsheet component, Michael Liebman decided to roll his own. This week he put out a call for contributors, seeking “experienced developers who can pick this up and turn it into something that everybody can use,” perhaps by converting it into a plugin. The code can be found at http://code.google.com/p/slickgrid/.

Tutorials

Steve Reynolds has posted a tutorial on how to create OS X Dashboard Widgets with jQuery. For those who want to know “What in the heck is JSONP and why would you use it?” Raymond Camden gives you the answers on the O’Reilly Inside RIA blog (hint: cross-domain ajax).

Quick Tip

We often see questions posted in the jQuery Google Group about why a jQuery script is “broken” in Internet Explorer when it works in all other tested browsers. By far the most common solution in these cases is to search for and then remove a trailing comma from the last key-value pair in an object literal:

var foo = {
  bar: 'ice cream',
  baz: 'luhrmann', // <-- get rid of that comma!
}

This can especially trip up developers who are used to other languages such as PHP, in which including the trailing comma is considered a “best practice.” JSLint is a great tool to run your JavaScript through periodically, as it does a great job of flagging these kinds of errors and warnings for you. If you use TextMate, the JavaScript Tools bundle runs a “quick JSLint” every time you save your JavaScript file and runs the full JSLint, along with a number of other conveniences, from the bundle’s menu.

Well, that’s it for this week. Be sure to check out This Week in jQuery UI, too!

25 thoughts on “This Week in jQuery, vol. 1

  1. Pingback: This Week in jQuery UI vol. 1 « jQuery UI Blog

  2. dafire on said:

    about the jslint quick tip… if you use komodo for editing your js files it does error checking in the background all the time.

  3. An addition to the quick tip:

    If you’re writing singleton objects (typically options in jquery/ui), and you have a value that you might change frequently, such as setting the active tab temporarily, it’s a good idea to ensure that value isn’t the last in the list.

    var options = {
    selected: 2,
    orientation: ‘vertical’
    };

    this way you can easily comment it out without having the extra comma issue addressed in the quick tip above.

    this example will cause errors in some browsers:
    var options = {
    orientation: ‘vertical’,
    //selected: 2
    };

    do this instead:
    var options = {
    //selected: 2,
    orientation: ‘vertical’
    };

  4. Pingback: 当心多余的逗号 | 走走停停看看

  5. Kevin Peno on said:

    RE the IE compatability problems. Another thing developers should do is turn on strict javascript warnings in browsers, such as firefox, during development. This will flag other issues that may also cause problems with compatability (including trailing commas last I checked), mostly in relation to syntax. That way when you test in IE, if it is not your primary development browser, you are less likely to run in to problems.

    I like the idea of this blog. I look forward to some cool tips and exposure of less popular, yet useful, plugins!

  6. @Gordon: yeah, I initially had written, “considered by some to be a best practice,” but I was afraid I was getting too wordy. Anyway, at least Drupal’s coding standards document recommends it: “Note the comma at the end of the last array element; This is not a typo! It helps prevent parsing errors if another element is placed at the end of the list later.” In retrospect, I probably should have gone with the much weaker statement that the trailing comma is “perfectly valid syntax,” as noted in the PHP Manual.

  7. Pingback: This Week in jQuery, vol. 1 | Ajax Guru - How to Ajax

  8. Pingback: 網站製作學習誌 » [Web] 連結分享

  9. I previously forced my users to switch to Firefox for the web app I’ve built if only for the speed increase (lots and lots of Ajax loads to recreate a Java program). A couple of runs through Jslint found the one errant comma and IE works now too.

    Then again, I almost want to the put the comma back to continue to force Firefox in hopes they will like it and get it at home too.

  10. I hope when the jQuery UI 1.8, a comprehensive add cookie function, the user just add $ ( ‘. Selector’). Tabs ((cookie: (expires: 7, path: ‘/’, domain: ‘jquery.com’, secure: true)));, not to allow users to go to write a lot of code.

  11. Howard Jess on said:

    An alternate syntax for object literals that can help avoid the trailing comma problem is nice (if you can get used to it):

    var foo = {
    bar: ‘ice cream’
    ,baz: ‘luhrmann’
    ,bongo: ‘feinman’
    }

  12. moby_dick on said:

    You can also use the following regex to find the wrong commas:

    ,[\s\r\n]*[\}\]]

  13. Pingback: Links For March 30 2009 | .Net

  14. Pingback: This Week in jQuery UI vol. 4 « jQuery UI Blog

  15. USA Locksmith provides fast,reliable,professional 24 Hour Emergency Locksmith services at extremely competitive rates.At USA Locksmith we stand behind our workmanship – 100% client satisfaction guaranteed.At USA Locksmith we have a fully equipped machine shop available 24 hours a day 7 days a week,we service most major lock brands and associated door hardware,including the brands we do not sell.

  16. revive on said:

    jQuery website is having errors.. even after logging in, this is the ONLY place I can access to make a comment !! Can’t post to issues. Can even click the issue queue for this website !!!
    How frustrating.. There is a bug in the Masked Input plugin (hence the reason for my posting here, since it was part of this blog post).. and I’d like to submit..
    After trying to access ANY part of the issues pages, and continuing to get ‘access denied’ errors.. I decided to signup to the forum.. which was success full but also result into a 404 page on redirect LOL..
    Too funny..