After Work
The best club in Chicago
for Chicago Singles is
Highlife Adventures!
Are you looking for a
Jersey Girl T-Shirt
?
Kyoto Sushi
in Chicago, on Lincoln Ave.
Moody's Pub
in Chicago, has great burgers
Skylark
in Chicago, on Halsted .. excellent Friday fish fry!
|
Javascript
»
Methods
»
Coding
»
Executing Dynamic Code
Javascript statement blocks can be created and executed using the eval
function. This is similar to dBase's macro prefix. The eval function
takes an argument as a string- this string can be a line of code, or a
variable, or any piece of Javascript that could execute in the given
context. Here is an example:
var myvar1=0
var myvar2=0
var myvar3=0
/* set all variables to 100 */
for (i=1;i<4;i++) {
eval("myvar" + i + "=100");
}
Here is another example, in which a function calls one of four different
functions based on the parameter:
function f_sort(parm1)
{
eval("array1.sort(f_compare" + parm1 + ");");
eval("prev1=loc" + parm1 + "1;");
eval("prev1=loc" + parm1 + "2;");
}
Using the eval function saved 9 lines of code in this case!.
|
|
|
|