DHTML Lab - dhtmlab.com - Hierarchical Menus Ver. 3 - Addendum IV (v3.04) | 3 | WebReference

DHTML Lab - dhtmlab.com - Hierarchical Menus Ver. 3 - Addendum IV (v3.04) | 3

Logo

Hierarchical Menus Ver. 3 - Addendum IV (v3.04)
the Navigator 4.5 eval() bug


Consider this function:

function doIt(arg) {
    arg = 5;
    eval("newVar = arg");
    document.fmArg.taArg.value +=
        "arg is: "+ arg +"; newVar is: "+ newVar +"\n";
}

The function doIt() is passed one argument, arg. Regardless of the passed value of arg, it is reassigned a value in the first statement:

arg = 5;

Now, it has a value of 5. All consequent function statements should work with this new value. Our second statement uses eval() to evaluate a string that assigns the value of arg to the newVar variable:

eval("newVar = arg");

When the statement is executed, newVar is created and should have a value of 5.

The final statement displays the values of arg and newVar in a text area, for demonstration purposes.

The form below uses the sample function, passing three different values for arg: 3, no value and null. Try it with Navigator 4.5 if you can, and with any other JavaScript-enabled browser. Compare the results.

function doIt(arg) {
    arg = 5;
    eval("newVar = arg");
    document.fmArg.taArg.value +=
        "arg is: "+ arg +"; newVar is: "+ newVar +"\n";
}