[Javascript] Good vs. Eval (was Form validation)

Jeff Greenberg jeff at websciences.org
Tue Jan 20 12:37:27 CST 2004


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.
>
>Original Message:
>  
>
>>From: "Chris Tifer" <christ at saeweb.com>
>>    
>>
>
>  
>
>>This is going off-topic, but for some reason I just hate eval(). I don't
>>believe I've ever found a need to use it.  There's always some other way...
>>
>>Chris Tifer
>>    
>>
>
>
>_______________________________________________
>Javascript mailing list
>Javascript at LaTech.edu
>https://lists.LaTech.edu/mailman/listinfo/javascript
>
>  
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20040120/d91adf81/attachment.htm>


More information about the Javascript mailing list