G
Gene Wirchenko
Dear JavaScripters:
I am writing an object for handling browser-side field
presentation and validation. Two of the properties will have string
values of code to be executed in order to do validation. The code
could be arbitrary, but it will probably be a function call with
parameters.
How do I handle this? I see three possibilities:
1) eval()
From what I have read, this might be better spelled "evil()", but
I have used similar functionality in another language. I am concerned
with scoping. I ran across one Web reference that stated that it
differs between browsers.
I want the scoping of the variables used to be as at the time of
execution of the validation code. The code will be executed inside
the object code so all of the properties will be available, and I will
-- unless required not to -- probably pass them to the validation
function called. I would like the validation code to be able to
change the value of a parameter or a global value.
One advantage of this approach is that I can append more code to
the string on the fly if I wish.
2) Define a function with new Function()
Something like
var myFunctionName = new Function(arg1, arg2,
"/* function content goes here */");
I do not think that I can append more code as with a string. (I
might not need this functionality, but I would like to keep the option
open if it is not too dear to do so.)
3) Something Else I Wot Not Of
wot: a short word for "know".
Maybe, you know of another way?
Sincerely,
Gene Wirchenko
I am writing an object for handling browser-side field
presentation and validation. Two of the properties will have string
values of code to be executed in order to do validation. The code
could be arbitrary, but it will probably be a function call with
parameters.
How do I handle this? I see three possibilities:
1) eval()
From what I have read, this might be better spelled "evil()", but
I have used similar functionality in another language. I am concerned
with scoping. I ran across one Web reference that stated that it
differs between browsers.
I want the scoping of the variables used to be as at the time of
execution of the validation code. The code will be executed inside
the object code so all of the properties will be available, and I will
-- unless required not to -- probably pass them to the validation
function called. I would like the validation code to be able to
change the value of a parameter or a global value.
One advantage of this approach is that I can append more code to
the string on the fly if I wish.
2) Define a function with new Function()
Something like
var myFunctionName = new Function(arg1, arg2,
"/* function content goes here */");
I do not think that I can append more code as with a string. (I
might not need this functionality, but I would like to keep the option
open if it is not too dear to do so.)
3) Something Else I Wot Not Of
wot: a short word for "know".
Maybe, you know of another way?
Sincerely,
Gene Wirchenko