See also: JSV_openDebugConsole, JSV_writeDebug2

The JSV_writeDebug function writes the character representation of a variable and its value to the debug console where it can be traced.

Syntax

JSV_writeDebug(expA, ...)

Returns

n/a

Parameters

The JSV_writeDebug function uses the following arguments.

Argument Description
expA Any number of arguments may be passed. These arguments are then concatenated into one string along with a line break (i.e., <br>). This new string is then written to the debug console.

Suggestion:

The first argument to be passed should be a string that identifies where the trace information is located in the JavaScript code. The user may want to trace the same variable in more than one place in the code. This identifier should be unique for each place to assit the user in tracing the variable.

The next argument would be a string respresentation of the variable being traced along with any other pertinent information. For example, if the value of the variable i is in question, then this argument might be "i = ", or "i (should equal 3 here) = ".

The next argument should then be the variable being traced. For example, if the value fo the variable i is in question, then this argument should be i.

(See example below.)

Remarks

The JSV_writeDebug2 function includes the name of the calling function in each line written to the debug console (see JSV_writeDebug2 example); otherwise, the JSV_writeDebug function writes only the information passed as arguments to the function to the debug console (see the JSV_writeDebug example).

The JSV_writeDebug and JSV_writeDebug2 functions write the debug information to the debug console. The difference between using the JSV_writeDebug and JSV_writeDebug2 functions and the JSV_documentWrite function is that the JSV_writeDebug and JSV_writeDebug2 functions makes sure that the the debug console is open (i.e., opens the debug console if it is closed) and in focus so the user can monitor the information being traced.

If the user wishes to use the JSV_documentWrite function with the JSV_openDebugConsole function to write whatever information the user deems necessary to debug the JavaScript, then the first argument to the JSV_documentWrite function should be jsvDebugConsole. This variable identifies the JavaScript Vision debug console.

The user should always conclude the test with a call to the JSV_documentClose function and possibly the JSV_focusWindow to alert the programmer that the script has ended and the trace is ready to be looked at to find the logical error. Both of these functions take jsvDebugConsole as an argument. (See example below.)

Dependencies

JSV_isWhitespace, JSV_openDebugConsole, JSV_documentWrite

Example

The following lines of code

function debugTest() {
    var startTestAt = new Date();
    JSV_writeDebug( "<B>Test of the JavaScript Vision Debug Console</B>", 
                    "<BR><B>Start Test:</B> ",
                    startTestAt.formatDate("mm/dd/yyyy hh:mm:ss")
                    );
    var i = 0, j = 0, k = 0;
    for (i=0; i<3; i++) {
        JSV_writeDebug("Debug 1:", "i = ", i);
        for (j=0; j<3; j++) {
            JSV_writeDebug("Debug 2:", "j = ", j);
            k = j + i;
            JSV_writeDebug("Debug 3:", "k = ", k);
        }
    }
    var endTestAt = new Date();
    JSV_writeDebug( "<B>End Test:</B> ",
                    endTestAt.formatDate("mm/dd/yyyy hh:mm:ss"),
                    "<BR>",
                    "<B>Elasped Time (seconds):</B>",
                    startTestAt.dateDiff(endTestAt, "s")
                    );
    JSV_documentClose(jsvDebugConsole);
    JSV_focusWindow(jsvDebugConsole);
}

produce a new window to which the debug information is written

Execute debugTest