HTML and CSS Reference
In-Depth Information
7.1.6 Functions Are Objects
For a discussion on how functions behave as objects. See “Classes and User-Defined
Functions” on page 182 in Chapter 8, “Objects.”
7.2 Debugging Techniques
Now that we have covered some of the fundamental JavaScript constructs, this is a good
time to introduce some debugging techniques. As your programs grow, so do your
chances to create errors. Getting to know how to deal with these problems will save you
much time and frustration.
7.2.1 Function Syntax
When working with functions there are some simple syntax rules to watch for:
1. Did you use parentheses after the function name?
2. Did you use opening and closing curly braces to hold the function definition?
3. Did you define the function before you called it? Try using the typeof operator
to see if a function has been defined.
4. Did you give the function a unique name?
5. When you called the function is your argument list separated by commas? If
you don't have an argument list, did you forget to include the parentheses?
6. Do the number of arguments equal to the number of parameters?
7. Is the function supposed to return a value? Did you remember to provide a vari-
able or a place in the expression to hold the returned value?
8. Did you define and call the function from within a JavaScript program?
Figure 7.17 shows function errors displayed by the JavaScript Error Console in
Firefox. This is a very useful debugging tool for immediate error checking. Just click the
Tools menu and go to Error Console. These error messages make troubleshooting your
scripts much easier. Figures 7.18 through 7.20 show errors in other browsers.
Figure 7.17 Function errors in the JavaScript Error Console (Firefox).
 
 
 
 
Search WWH ::




Custom Search