|
|
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 3 of 7
Want more programming tutorials and news? Get the JavaWorld Enterprise Java newsletter delivered to your inbox.
Many logic errors are caused by incorrect values in variables. One way to help you spot these logic errors is to set "watchpoints" at one or more spots in the script. These watchpoints are alert boxes that display the contents of the variables. You can also use alert boxes to determine if your code is reaching a certain point in the program. (I use something like alert("to here") to verify the code is working.) Remove the alert watchpoints after the script has been debugged.
A little-known JavaScript testing shortcut is to type a JavaScript command line in Navigator's Location box. Preface the command
line with the JavaScript: protocol, like that shown below, and press the Enter key to see the result:
javascript:alert ("this is a test")
Note that not all command lines provide meaningful results. For example, typing
javascript:document.write ("this is a test")
and pressing Enter results in true printed in the document window.
If you need to test a number of command lines, you can reduce the keystrokes by typing javascript: (remember the colon) in the Location box. Navigator displays a "JavaScript typein" frame at the bottom of the window. Type
the command line you want to try, and press Enter.
The "JavaScript typein" frame window described above is defined within Navigator. You can create your own version of it to allow for simplistic multiple-line command entry (this script is very basic and can be improved, but it serves to get you going). The following displays a multiline JavaScript typein utility. The multiline command entry script is a combination frameset and JavaScript-generated frame document. To use, type the script segment you want to test in the text-area box, and choose Run.
Note: When using this script be sure to append semi-colons (;) at the end of each line. This helps JavaScript properly parse the command lines you enter.
<SCRIPT>
function jsinput () {
parent.MochaInput.document.write ("<b>JavaScript input</b>")
parent.MochaInput.document.write ("<form action=JavaScript: target=MochaOutput>")
parent.MochaInput.document.write ("<textarea name='isindex' rows=5 cols=50>")
parent.MochaInput.document.write ("</textarea><BR>")
parent.MochaInput.document.write ("<input type='submit' value='Run'>")
parent.MochaInput.document.write ("</form>")
}
</SCRIPT>
<FRAMESET ROWS="50%%,50%%">
<FRAME NAME="MochaOutput" SRC="about:blank">
<FRAME NAME="MochaInput" SRC="javascript:parent.jsinput()">
</FRAMESET>
JavaScript programs are composed of text embedded in HTML documents. Therefore, you can use any text editor program that has a print capability to make paper copies of your scripts. The paper copies may help you find errors that are otherwise hidden in screenfuls of code displayed on your monitor.