[Javascript] Good vs. Eval (was Form validation)
Peter Brunone
peter at brunone.com
Tue Jan 20 12:54:58 CST 2004
But how do you get the array to point to the *execution* of the function rather than the return value of the function? That is, if I want to set functionList["myFunction"] equal to myFunction(), how do I get it in there so that I can use it?
IMO, this is a great discussion; keep it coming!
Original Message:
>From: Jeff Greenberg <jeff at websciences.org>
>One of the easiest ways to call a function based on a string is to index
>into an array or an object like so:
>
>functionList["myFunction"]();
>
>eval is not inherently bad or inefficient, it is just often used
>improperly or in cases where more thought should go into the design and
>architecture of the code. It is, in fact, indispensible if you are
>trying to extend the core javascript language or work with dynamically
>generated/modified code. It should not be used in "every day" code, and
>if you find yourself using it in a small bit of code, it is likely you
>are misusing it. Nothing is set in stone of course, and this is just a
>general guideline.
>
>Peter Brunone wrote:
>
>> No problem; just start a new thread!
>>
>> What if you want to run a function based on a string?
>>
>>-Peter B.
More information about the Javascript
mailing list