HTML, XHTML and CSS All-In-One for Dummies - Andy Harris [131]
Don’t go telling people you’re programming in Java. Java people love to act all superior and condescending when JavaScript programmers make this mistake. If you’re not sure, ask a question on my Web page. I can help you with either language.
♦ It’s a scripting language. As programming languages go, JavaScript’s pretty friendly. It’s not quite as strict or wordy as some other languages. It also doesn’t require any special steps (such as compilation), so it’s pretty easy to use. These things make JavaScript a great first language.
Choosing a JavaScript editor
Even though JavaScript is a programming language, it is still basically text. Because it’s normally embedded in a Web page, you can work in the same text editor you’re using for XHTML and CSS. If you aren’t already, I recommend that you use the powerful Aptana editor. Aptana is great for XHTML and CSS, but it’s very useful when you use it to incorporate JavaScript code in your pages.
JavaScript is an entirely different language and syntax than HTML and CSS. It isn’t hard to learn, but there’s a lot to learning any programming language. Aptana has a number of great features that help you tremendously when writing JavaScript code:
♦ Syntax highlighting: Like HTML and CSS, Aptana automatically adjusts code colors to help you see what’s going on in your program. As you see in the later sidebar “Concatenation and your editor,” this adjustment can be a big benefit when things get complicated.
♦ Code completion: When you type the name of an object, Aptana provides you with a list of possible completions. This shortcut can be really helpful because you don’t have to memorize all the details of the various functions and commands.
♦ Help files: The Start page (available from the File menu if you’ve dismissed it) has links to great help pages for HTML, CSS, and JavaScript. The documentation is actually easier to read than some of what you’ll find on the Web.
♦ Integrated help: Hover the mouse on a JavaScript command or method, and a nifty little textbox pops up to explain exactly how the feature works. Often, it even includes an example or two.
♦ Error warnings: When Aptana can tell something is going wrong, it gives you an error message and places a red squiggly (such as the one spell checkers use) under the suspect code.
While Aptana is a very good choice, not everyone likes it. I’m also a big fan of Komodo edit, which has all the same features as Aptana, works on any OS, and is a little bit faster than Aptana. If you find Aptana too complicated, take a look at Komodo and see if it fits your style better.
Of course, you can use any text editor if you don’t want or need those features. Any of the following text editors (all mentioned in Book I, Chapter 3) are suitable for JavaScript work:
♦ Notepad++
♦ VI / VIM
♦ Emacs
♦ Scintilla
♦ jEdit
There’s one strange characteristic I’ve noticed in Aptana. The Preview tab isn’t as reliable a technique for checking JavaScript code as it was in XHTML and CSS. I find it better to run the code directly in my browser or use the Run button to have Aptana run it in the external browser for me.
Picking your test browser
In addition to your editor, you should think again about your browser when you’re testing JavaScript code. All the major browsers support JavaScript; and the support for JavaScript is relatively similar across the browsers (at least for the stuff in this chapter). However, browsers aren’t equal when it comes to testing your code.
Things will go wrong when you write JavaScript code, and the browser is responsible for telling you what went wrong. Firefox is way ahead of Internet Explorer when it comes to reporting errors. Firefox errors are much easier to read and understand,