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

Peter Brunone peter at brunone.com
Tue Jan 20 11:50:19 CST 2004


   First off, let me make it clear that I'm not against eval(), but knowing how Chris feels about the subject, I couldn't resist the pun.

   For your example, why wouldn't you just make a pointer to each object instead of using a string and having to re-evaluate it again?  You're going to have to write out the reference to the object at some point, whether you use eval or not.

   In my case, I'm building a compiled server control where the user can tell it to do a certain thing onchange; I could write out the function call instead of storing it for evaluation, but I don't know what the function will be ahead of time, and if there are multiple controls on a page, I need to be flexible.  Sure, there may be a better way, but you know what they say about "best" and "good enough"...

Cheers,

Peter

Original Message:
>From: "allard schripsema" <allard-schripsema at procergs.rs.gov.br>

>I don´t know if I´d call this thread good vs eval  but here i go:
>
>What would you prefer?
>
>compare(parent.frame2.formWhatever.Input1,parent.document.formWhatever.Input
>2)
>or
> compare(sInput1,sInput2)
>readability is one reason to pass strings instead of objects and do the eval
>afterwards.
>
>Another reason  may be that you gain productivity if you accept both strings
>and objects in functions in your codelibrary (we have 400+ functions).
>Programmers won´t have to guess/ lookup what is expected.
>
>Coding with Eval is much more efficient than for example switch / case.
>Remember that every character goes though the internet.
>
>----- Original Message ----- 
>From: "Matt Barton" <javascript at mattbarton.org>
>
>> I'm inclined to agree.  I've never had cause to do that (call a function
>> based on contents of a string variable) in Javascript, but exactly the
>same
>> thing is possible in PHP.  In my darker moments I have been known to us
>it,
>> but I've never liked to.  It's normally the result of a bad code design
>> descision I have made in the past which I've neither the time or
>inclination
>> to resolve.
>>
>> Just as evil is $$variablename.  But that's not just another thread, it's
>> another mailing list...
>>
>> Matt
>>
>> ----- Original Message ----- 
>> From: "Chris Tifer" <christ at saeweb.com>
>> >
>> > To me, this goes back to "There's always some other way..."
>> >
>> > :)
>> >
>> > Chris Tifer





More information about the Javascript mailing list