R
Randy Webb
(e-mail address removed) said the following on 6/13/2006 12:56 AM:
That is not what eval is "most often used for" though. You see it a lot
when people are trying to do what the document refers to - accessing
without using Square Brackets.
Suppose you are using dynamic element ID's or don't know the ID (it is
passed to a function). Instead of writing this:
document.forms['formID'].elements[elementName].value;
You see people do this - a lot:
eval('document.formID.'+elementName+'.value')
Same goes with any other Dot Notation usage where the Name or ID is not
know but is passed in.
You also see it in some of Macromedia's functions.
And from the best practices document, regarding eval:
It seems to me that it's most often used to evaluate JSON in response
to an XmlHttpRequest call. Why is this a bad idea?
That is not what eval is "most often used for" though. You see it a lot
when people are trying to do what the document refers to - accessing
without using Square Brackets.
Suppose you are using dynamic element ID's or don't know the ID (it is
passed to a function). Instead of writing this:
document.forms['formID'].elements[elementName].value;
You see people do this - a lot:
eval('document.formID.'+elementName+'.value')
Same goes with any other Dot Notation usage where the Name or ID is not
know but is passed in.
You also see it in some of Macromedia's functions.