473,503 Members | 3,171 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to use eval?

var fns = ['orde', 'no', 'kml', 'snf', 'td', 'ty', 'tn', ...up to 21
elms...];
var snv = new Array();

var vals = new Array();
for (i = 0; i < N; i++) {
for (j = 0; j < fns.length; j++)
vals[j] = some value;
snv[i] = new makeData(vals);
}

function makeData(vals) {
for (k = 0; k < vals.length; k++)
//the following line doesn't work
eval("this."+fns[k]+"="+vals[k]);
//neither this one
this.eval(fns[k]) = vals[k]);
}

how can i make it without writing it the long way:

this.orde = vals[0];
this.no = vals[1];
this.kml = vals[2];

and so on?
Jul 23 '05 #1
7 1164
Lee
Andy LW said:

var fns = ['orde', 'no', 'kml', 'snf', 'td', 'ty', 'tn', ...up to 21
elms...];
var snv = new Array();

var vals = new Array();
for (i = 0; i < N; i++) {
for (j = 0; j < fns.length; j++)
vals[j] = some value;
snv[i] = new makeData(vals);
}

function makeData(vals) {
for (k = 0; k < vals.length; k++)
//the following line doesn't work
eval("this."+fns[k]+"="+vals[k]);
//neither this one
this.eval(fns[k]) = vals[k]);
}

how can i make it without writing it the long way:

this.orde = vals[0];
this.no = vals[1];
this.kml = vals[2];


this[fns[k]] = vals[k];

But that seems like an odd thing to want to do.

Jul 23 '05 #2


--
Neither by ship nor on foot could you find the marvellous road to the
meeting-place of the Hyperboreans.
pindar, pythian odes, 10.

"Lee" <RE**************@cox.net>, haber iletisinde þunlarý
yazdý:d6*********@drn.newsguy.com...
Andy LW said:

var fns = ['orde', 'no', 'kml', 'snf', 'td', 'ty', 'tn', ...up to 21
elms...];
var snv = new Array();

var vals = new Array();
for (i = 0; i < N; i++) {
for (j = 0; j < fns.length; j++)
vals[j] = some value;
snv[i] = new makeData(vals);
}

function makeData(vals) {
for (k = 0; k < vals.length; k++)
//the following line doesn't work
eval("this."+fns[k]+"="+vals[k]);
//neither this one
this.eval(fns[k]) = vals[k]);
}

how can i make it without writing it the long way:

this.orde = vals[0];
this.no = vals[1];
this.kml = vals[2];


this[fns[k]] = vals[k];

But that seems like an odd thing to want to do.


it works. thank you.

Jul 23 '05 #3
Andy LW wrote:


Please don't put your sig at the top of your message, most good newsreader
and email software automatically trims it, so the entire content of your
message is lost! You might find it useful to install OE Quote Fix.

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Jul 23 '05 #4

"David Dorward" <do*****@yahoo.com>, haber iletisinde sunlari
yazdi:d6*******************@news.demon.co.uk...
Andy LW wrote:


Please don't put your sig at the top of your message, most good newsreader
and email software automatically trims it, so the entire content of your
message is lost! You might find it useful to install OE Quote Fix.

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is


i usually delete it (as i did in my first message), but that i forgot.
Jul 23 '05 #5
David Dorward wrote:
Andy LW wrote:



Please don't put your sig at the top of your message, most good newsreader
and email software automatically trims it, so the entire content of your
message is lost! You might find it useful to install OE Quote Fix.


You've got me wondering how he's managed to get OE to preserve the ' '
of '-- ' without OEQF.

Stewart.

--
My e-mail is valid but not my primary mailbox. Please keep replies on
the 'group where everyone may benefit.
Jul 23 '05 #6
JRS: In article <d6*******************@news.demon.co.uk>, dated Wed, 18
May 2005 07:56:16, seen in news:comp.lang.javascript, David Dorward
<do*****@yahoo.com> posted :
Andy LW wrote:


Please don't put your sig at the top of your message, most good newsreader
and email software automatically trims it, so the entire content of your
message is lost! You might find it useful to install OE Quote Fix.


But *good* software will only trim it from replies (*really* good
software would IMHO leave it present but greyed and copyable but not
editable, and would remove the greyed lines at the point of transmission
as news/mail).

To trim it from the version presented for reading would be ludicrous.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME ©
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Jul 23 '05 #7
Stewart Gordon schrieb:
David Dorward wrote:
Please don't put your sig at the top of your message, most good
newsreader and email software automatically trims it, so the
entire content of your message is lost! You might find it useful
to install OE Quote Fix.


You've got me wondering how he's managed to get OE to preserve the
' ' of '-- ' without OEQF.


No Content-Type heade, no character declaration or
`Content-Type: ...; charset=us-ascii' will "allow"
this in OE.
PointedEars
Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
4077
by: Reply Via Newsgroup | last post by:
This might sound sad... someone requesting a disertation on the 'eval' statement... but... I've been reading someone else's post - they had a huge calander like script and a handful of folk cursed...
11
1842
by: sneill | last post by:
I have read a number of posts on the use of eval() in Javascript, and I agree that its use is questionable. But it does beg the following question: "How arbitrary does a string need to be before...
0
3802
by: Michelle Keys | last post by:
Subject: DataBinder.Eval Error! Server Error in '/MSPOS' Application. ------------------------------------------------------------------------ -------- DataBinder.Eval:...
18
3136
by: Joe Fallon | last post by:
I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My...
15
3642
by: manstey | last post by:
Hi, I have a text file called a.txt: # comments I read it using this:
3
1890
by: Pauljh | last post by:
Hi All, I'm running some javascript over a server side generated web page and have multiple generated empty select statements, that I want to populate when the page is loaded. As HTML doesn't do...
4
2756
by: Jm lists | last post by:
Hello members, I want to know does the "eval" in python have the same features as in Perl (capture errors)? For example,in perl I can wrote: $re = eval { 1 / 0 }; Though 1/0 is a fatal...
6
5882
by: RandomElle | last post by:
Hi there I'm hoping someone can help me out with the use of the Eval function. I am using Access2003 under WinXP Pro. I can successfully use the Eval function and get it to call any function with...
5
6616
by: wendallsan | last post by:
Hi all, I'm running into a situation where it seems that JS stops executing as soon as I call an eval in my script. I have an Ajax.Request call to a PHP page that builds a JS object and returns...
10
494
by: Gordon | last post by:
I have a script that creates new objects based on the value of a form field. Basically, the code looks like this. eval ('new ' + objType.value + '(val1, val2, val3'); objType is a select with...
0
7063
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7258
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7313
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7441
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5558
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4987
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4663
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3156
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
366
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.