eval stuff (was Re: [thelist] testing for empty in javascript or vbscript)
.jeff
jeff at members.evolt.org
Mon Jul 15 22:35:02 CDT 2002
shanx,
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: Shashank Tripathi
>
> Before I rant on with my lame defence, you may like to
> see this:
> http://erudition.com/eval.gif
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
nice.
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> Being a devout RTFM freak, I usually just read the
> netscape JS docs and MSDN, which are both adequately
> detailed.
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
you have seen some of danny's work then, without even knowing it. he's
responsible for the expand/collapse tree that makes up the navigation for
the netscape js docs.
view-source:http://developer.netscape.com/docs/manuals/js/client/jsref/toc.h
tm
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> We had to validate these forms on the client-side as
> well as the server-side. Since the names of these form
> elements were generated at run time including the number
> of the row etc, validating them on client side needed
> their element name (e.g., document.calcForm.res12.value
> .... where the X in resXY was the row, and the Y was
> the column of the input element). The validation was
> dependent on the number of the row not just the
> element's column, the rules for which came from an
> external "BusinessRules.ini" file..which converted
> into JS functions at run-time.
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
it's done now, but using bracket notation would have saved you a ton of
trouble.
document.calcForm.elements['res' + x + y].value let's you grab the value of
a particular field based on the values of x and y.
there just isn't any need to use eval() in this instance.
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> I may look like I am scrambling to prove a point (well,
> and that would partly be right! :)) but just giving you
> an example of a good case where eval is pretty useful.
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
only because the basic constructs of javascript weren't understood (no
offense).
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> FWIW, functions like eval() in server side languages
> are quite voted against as well, but pretty useful
> sometimes.
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
they can be pretty useful at the time of development, but will negatively
affect performance and code readability should you need to debug or add to
the code later.
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> For instance, if you wish to save your error messages
> etc in a separate config file, but want some dynamic
> variable to be a part of that message during run time.
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
sounds like a poor/lazy man's function to me. i could understand the use of
an eval() method in this situation, but if you're using most any decent
server-side language you could have just as easily written your own function
to do the work for you.
just my 2¢,
.jeff
http://evolt.org/
jeff at members.evolt.org
http://members.evolt.org/jeff/
More information about the thelist
mailing list