Debugging Kỹ thuật Bây giờ chúng ta có được một số các JavaScript cơ bản xây dựng, đây là thời điểm tốt để giới thiệu một số kỹ thuật gỡ lỗi. Như các chương trình của bạn phát triển, do đó, cơ hội của bạn để tạo ra lỗi. Tìm hiểu làm thế nào để đối phó với những vấn đề này sẽ giúp bạn tiết kiệm nhiều thời gian và thất vọng. | 166 Chapter 7 Functions 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. 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. 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 variable 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 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 through show errors in other browsers. Figure Function errors in the JavaScript Error Console Firefox . From the Library of 72 Debugging Techniques 167 Figure Windows Internet Explorer Look in the bottom left corner of the page. Double-click the yellow icon. A window will appear with the line and character where the error was found. Figure Windows Internet Explorer Debug .