specializing in digital media technologies

Digital Media and Communications Insights, Inc.


Larry Ullman's Blog

JavaScript Block Comments

I ran across an interesting little tidbit in a JavaScript book, I think, or online. Likely I saw it in something Douglas Crockford wrote, but couldn’t be certain. Anyway, it has to do with comments in JavaScript. The language supports two comment types:

1. Single line using the double slash:

// This is a comment.

2. Multiline (also called block) using the slash-asterisk combination:

/* This comment
can go over multiple
lines. */

The argument made (wherever it was made) is that you shouldn’t use the multiline comment style as the */ character combination can appear in JavaScript code. Namely, it might appear in a regular expression match, when slashes are used to delineate the pattern and the asterisk is a pattern modifier that looks for zero or more of something. A syntax error will arise if you use block comments around some code that includes a problematic regular expression:

/* some code
var x = 'some string'.search(/[a-z]*/g);
some code */

That’s obviously a useless example in itself, but it shows a situation in which a problem is caused by using block comments.

All that being said, I wouldn’t suggest that you avoid using multiline comments. They’re quite handy, both for adding lots of documentation and for debugging purposes (by making blocks of code inert). But the potential conflict is something to be aware of, particularly when you apply multiline comments to render some code non-executing and all of a sudden have a syntax problem.

Filed under: JavaScript

Ajaxload

I StumbledUpon a notable Ajax resource recently, called Ajaxload. This site provides tools for generating an animated GIF that can be used on your site to indicate that something is loading or happening or whatever. Choose a style you like, the background color, the foreground color, and the transparency of the background, then click “Generate it!” and you have a nice, custom graphic. The site’s in beta now and is free; I’m not sure if it’ll remain so or not (hopefully it will).

Filed under: JavaScript, Web Development — Tags:

jQuery Tips, Tricks, and Miscellaneous

This entry is part 8 of 8 in the series Introduction to jQuery

In this, the last post in my series on jQuery, I mention an odd lot of interesting things about jQuery that are worth knowing. Some involve specific code; others aid understanding of jQuery’s philosophy. You may or may not want to also read these earlier posts on jQuery:

  1. Incorporating jQuery into an HTML page
  2. Selecting page elements
  3. Adding event handlers
  4. Applying effects
  5. Manipulating elements
  6. Ajax
  7. Plug-ins

(continue reading…)

Filed under: JavaScript, Web Development — Tags: , ,


Page 1 of 612345...Last »

If you have a question, are seeking information, want to download files, or generally have any need related to a specific book, please make sure you are using the correct link. Check both the title and the edition.