Appendix A. JavaScript Tools You Should Know

JavaScript is a young language in many ways. Although it has been around for about 15 years, only recently has it been used for large-scale projects. So the tools to help programmers do robust, debuggable programming are still being developed. Here are a few you should strongly consider using.

JSLint

This is Douglas Crockford’s JavaScript syntax checker. JSLint can test JavaScript code for all manner of possible problems. You can run JSLint from the website (http://jslint.com) or locally. There is a Drag and Drop widget in the Yahoo! widget set, and you can run it from the command line with Rhino (discussed later). A simple bash script will make this easy to run (see Example A-1). You can even hook JSLint into your editor.

If you use one tool for JavaScript, it should be this one. To understand why, read Crockford’s JavaScript: The Good Parts. That book describes in detail why JSLint makes the choices it does. It will catch many very common JavaScript bugs and should be considered a key part of every JavaScript programmer’s tool set.

To configure JSLint on a per-file basis, you can put comments at the top of the file. These can turn options on or off in the file as well as tell JSLint about global variables that are defined elsewhere.

Example A-1. JSLint shell wrapper

        #!/bin/bash

java -jar ~/bin/rhino/js.jar ~/bin/jslint.js $1
JSMin

It’s a fact of life for JavaScript programmers that our programs are downloaded in source form to the user’s web ...

Get Programming HTML5 Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.