After Work
Old Town Social
in Chicago, on North Ave, near Cleveland. Great selection of tap beers.
Kyoto Sushi
in Chicago, on Lincoln Ave.
Moody's Pub
in Chicago, has great burgers
Skylark
in Chicago, on Halsted .. excellent beer selection!
|
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!.
|
|
|
Get the latest Rocket99 news and tech tips via
|