Get rid of 'eval'

P

Proper

This is a question to those who mean 'eval is evil'. I'm one of those.
However, I cannot answer my question. ;-)

Have a look at this page

http://home.arcor.de/pil/show-gallery.html?p=clouds

You'll notice that a parameter is passed through the URL. This is
necessary to choose the appropriate picture category. Therefore there
are three or four 'eval' inside the script.

The question is: How can this be done without 'eval'?
 
S

Stanimir Stamenkov

Mon, 6 Oct 2008 08:57:06 -0700 (PDT), /Proper/:
Have a look at this page

http://home.arcor.de/pil/show-gallery.html?p=clouds

You'll notice that a parameter is passed through the URL. This is
necessary to choose the appropriate picture category. Therefore there
are three or four 'eval' inside the script.

The question is: How can this be done without 'eval'?

eval('pics.'+ category +'.length') == pics[category].length

eval('pics.'+ category +'[nr].path') == pics[category][nr].path
 
D

dhtml

Stanimir said:
Mon, 6 Oct 2008 08:57:06 -0700 (PDT), /Proper/:
Have a look at this page

http://home.arcor.de/pil/show-gallery.html?p=clouds

You'll notice that a parameter is passed through the URL. This is
necessary to choose the appropriate picture category. Therefore there
are three or four 'eval' inside the script.

The question is: How can this be done without 'eval'?

eval('pics.'+ category +'.length') == pics[category].length

eval('pics.'+ category +'[nr].path') == pics[category][nr].path

Right.

The question is also answered in the FAQ:
http://jibbering.com/faq/#propertyAccess
http://jibbering.com/faq/#eval

Also see:
http://www.jibbering.com/faq/faq_notes/square_brackets.html
 
D

Dr J R Stockton

In comp.lang.javascript message <c3023857-d4bc-4b35-868c-39b544845219@f7
7g2000hsf.googlegroups.com>, Tue, 7 Oct 2008 02:46:43, Henry
On Oct 7, 4:36 am, dhtml wrote:

<snup> ^^^^^^^^^^^^^^^

These fragment identifiers are non-functional in IE 6. As IE 6 is
still in common use you should either correct them so that they are
functional or abandon using them.

Would http://jibbering.com/faq/index.html#propertyAccess be
functional in IE6 etc.?; memory suggests yes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top