[thelist] testing for empty in javascript or vbscript

.jeff jeff at members.evolt.org
Mon Jul 15 20:59:01 CDT 2002


shanx,

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: Shashank Tripathi
>
> | the eval() function is WAY WAY overused by
> | programmers.
>
> Agreed!
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

i'll third that one.

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> Who's Danny Goodman?
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

like whoa!

he's probably one of the most noted javascript authors on the planet.  he's
written for netscape, o'reilly's, and a slew of others.  (pssst, it's ok
danny.  some of us old-school js'ers still remember).

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> But eval is way way useful if you are drawing a lot of
> Javascript dynamically.
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

the eval() function is still a crutch, no matter how many other naughty
things you're doing in your scripting.  it's unnecessary and makes the code
highly unreadable.

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> For an intranet system, where we could settle for
> IE-only solution, eval() was almost indispensible.
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

indispensable?

hardly.  i have *yet* to find a situation where the use of eval() a) was
necessary to do something that couldn't be done more efficiently some other
way or b) made the code easier to read, debug, and otherwise maintain.

the true power of javascript lies in the ability to access practically
object and property via bracket ([]) notation.  once you understand this
you'll probably never find the need to use the eval() method again.

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> Besides, sometimes, a server side language will impose
> constraints on you that will go against the grain of
> coding puritanism..e.g., I don't like to call my radio
> buttons "myradio[]" (with those braces) but I have to
> do it in PHP.
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

there is no "have to".

;p

in fact, using brackets in your form element names is not valid and can
cause all sorts of other problems.  the only reason php'ers use the brackets
is because it removes a step in the setup of the form data for processing.
that's because when php encounters a fieldname ending in brackets it
converts it to an array.  however, you can name your fields properly and
just convert the fields you know will be coming across as a list (same named
elements like checkboxes or multi-select lists) to an array just before
processing.  the use of the brackets just shortcuts that step at the expense
of a document that won't validate and form field names that will wreak havoc
with client-side scripting.

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> Why did I wake up today! Its raining/storming/typhooning
> out here in Tokyo like there's no tomorrow. How's that
> for an eval(weather)... :)
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

sounds more like a self['weather'] to me.

;p

.jeff

http://evolt.org/
jeff at members.evolt.org
http://members.evolt.org/jeff/





More information about the thelist mailing list