how to use eval?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andy LW

    #1

    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."+fn s[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?


  • Lee

    #2
    Re: how to use eval?

    Andy LW said:[color=blue]
    >
    >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."+fn s[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];[/color]

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

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

    Comment

    • Andy LW

      #3
      Re: how to use eval?



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



      "Lee" <REM0VElbspamtr ap@cox.net>, haber iletisinde þunlarý
      yazdý:d6dmqf02o lb@drn.newsguy. com...[color=blue]
      > Andy LW said:[color=green]
      >>
      >>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."+fn s[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];[/color]
      >
      > this[fns[k]] = vals[k];
      >
      > But that seems like an odd thing to want to do.
      >[/color]

      it works. thank you.



      Comment

      • David Dorward

        #4
        [Meta] sigs (was Re: how to use eval?)

        Andy LW wrote:
        [color=blue]
        >
        >[/color]

        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

        Comment

        • Andy LW

          #5
          Re: [Meta] sigs (was Re: how to use eval?)


          "David Dorward" <dorward@yahoo. com>, haber iletisinde sunlari
          yazdi:d6ep56$mr c$2$830fa17d@ne ws.demon.co.uk. ..[color=blue]
          > Andy LW wrote:
          >[color=green]
          >>
          >>[/color]
          >
          > 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[/color]

          i usually delete it (as i did in my first message), but that i forgot.


          Comment

          • Stewart Gordon

            #6
            Re: [Meta] sigs (was Re: how to use eval?)

            David Dorward wrote:[color=blue]
            > Andy LW wrote:
            >
            >[color=green]
            >>[/color]
            >
            > 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.[/color]

            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.

            Comment

            • Dr John Stockton

              #7
              Re: [Meta] sigs (was Re: how to use eval?)

              JRS: In article <d6ep56$mrc$2$8 30fa17d@news.de mon.co.uk>, dated Wed, 18
              May 2005 07:56:16, seen in news:comp.lang. javascript, David Dorward
              <dorward@yahoo. com> posted :[color=blue]
              >Andy LW wrote:[color=green]
              >>[/color]
              >
              >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.[/color]

              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.demo n.co.uk/news-use.htm> : about usage of News.
              No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.

              Comment

              • Thomas 'PointedEars' Lahn

                #8
                Re: [Meta] sigs (was Re: how to use eval?)

                Stewart Gordon schrieb:
                [color=blue]
                > David Dorward wrote:[color=green]
                > > 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.[/color]
                >
                > You've got me wondering how he's managed to get OE to preserve the
                > ' ' of '-- ' without OEQF.[/color]

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


                PointedEars

                Comment

                Working...