Thoughts from the office by Ed Ball
Tuesday, March 01, 2005

JavaScript: The Definitive Guide, by David Flanagan, is an outstanding book about the JavaScript language. It has excellent documentation on both the “core” JavaScript language and “client-side” JavaScript as used by a web browser. Best of all, it doesn’t mix the two, which is particularly useful if you find yourself using JavaScript outside of a browser. It also gives the author a chance to dig deep into the core language, which is a far more powerful and expressive language than most people realize.

The second half of the book consists of three references – one for “core” JavaScript, one for “client-side” JavaScript, and one for the W3C DOM. The references aren’t nearly as useful as the first half of the book, since that sort of documentation is more widely available, but it could come in handy.

I have extensive experience using JavaScript both inside and outside of a browser, and have recently been studying the more “advanced” features. I was surprised by some of the details I had overlooked:

  • The switch statement uses identity (===), not equality (==), when looking for a matching case statement.
  • Each case of a switch statement can use any expression (not just numbers or strings).
  • The first expression of a for...in statement is evaluated for each item. (I don’t plan on taking advantage of that obscure feature.)
  • You can break or continue to a label.
  • FunctionName.length is the declared number of function arguments.
  • If a function used as a constructor returns an object, that object becomes the “new” object.
  • The push method of an Array can take multiple arguments.
  • In client-side JavaScript, “global” variables become properties of the global object, the window.
  • SCRIPT elements should use DEFER if they don’t call document.write.
  • The Internet Explorer event model has important differences from the standard event model.
  • The standard Error object simply takes a string in its constructor (in Internet Explorer, the Error constructor is documented as taking a number followed by the message; I have since discovered that the standard behavior is supported as well).
  • The substr method of String is deprecated in favor of substring or slice. (Unfortunately, I find substr far more natural than substring or slice.)
  • There are a lot of methods that only work in Internet Explorer (and this book only scratched the surface).

The book also talks some about “Object-Oriented JavaScript,” which I hope to talk more about in a future post.

If you are a JavaScript programmer but realize that you may only be scratching the surface of what is possible, or wonder why the language doesn’t always behave as you’d expect it to, I highly recommend that you read this book.

3/1/2005 1:36:27 PM (Pacific Standard Time, UTC-08:00) | Comments [0] | Books | JavaScript#
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Search
Archive
Links
Categories
Administration
Blogroll