eval

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

    #16
    Re: eval


    Thomas 'PointedEars' Lahn <PointedEars@we b.de> wrote in message
    news:bobps6$1c0 h2d$3@ID-107532.news.uni-berlin.de...[color=blue]
    > Stuart wrote:
    >[color=green]
    > > Thomas 'PointedEars' Lahn <PointedEars@we b.de> wrote [...][color=darkred]
    > > > However, [eval(...) is] still bad style.[/color]
    > >
    > > [...] May be it is "bad style" but I am new to javaScript, so may be you
    > > could point me in the way of "Good Style" and the correct way of
    > > scripting.[/color]
    >
    > I already did, what part of it did you not understand?[/color]

    I see nothing worthwhile that you have sugested!
    [color=blue]
    >
    > Maybe if you would shorten the quotes to what is required for following[/color]
    the[color=blue]
    > discussion, which saves disk space and bandwidth, and eases reading, you
    > were forced to read postings more thoroughly:[/color]


    If you are so concerned about bandwidth, why have you posted a somewhat
    pointless reply TWICE ??




    Comment

    • Thomas 'PointedEars' Lahn

      #17
      Re: eval

      Stuart wrote:
      [color=blue]
      > Thomas 'PointedEars' Lahn <PointedEars@we b.de> wrote [...][color=green]
      >> Stuart wrote:[color=darkred]
      >> > [...] May be it is "bad style" but I am new to javaScript, so may be you
      >> > could point me in the way of "Good Style" and the correct way of
      >> > scripting.[/color]
      >>
      >> I already did, what part of it did you not understand?[/color]
      >
      > I see nothing worthwhile that you have sugested![/color]

      You may want to re-read <news:bobmpr$1c 3igv$1@ID-107532.news.uni-berlin.de>
      [color=blue][color=green]
      >> Maybe if you would shorten the quotes to what is required for following[/color]
      > the[/color]
      ^^
      Your newsreader is b0rken. Please read

      and fix it.
      [color=blue][color=green]
      >> discussion, which saves disk space and bandwidth, and eases reading, you
      >> were forced to read postings more thoroughly:[/color]
      >
      > If you are so concerned about bandwidth, why have you posted a somewhat
      > pointless reply TWICE ??[/color]

      I did not. Please get informed about control messages like Cancel.
      And BTW, it would do you no harm to get informed about Usenet and
      the recommended behaviour in this discussion medium anyway before
      accusing people of spamming you that are actually trying to help
      you, despite a lack of minimum clue about the topic on your side.


      PointedEars, Score adjusted

      Comment

      • Douglas Crockford

        #18
        Re: eval

        > > > > Who told you to use eval()?[color=blue][color=green][color=darkred]
        > > > >
        > > > I am trying anything....inc luding asking you!
        > > > Are you getting the jist of what I am trying to achieve?[/color]
        > >
        > > It is almost always extremely wrong to use eval().
        > > Who is teaching you to program so badly?[/color][/color]
        [color=blue]
        > And your input has been ?????[/color]

        My input is that you should file a lawsuit against whoever it was who taught you
        to program. I think you may be entitled to significant damages.

        Comment

        • HikksNotAtHome

          #19
          Re: eval

          In article <bobmpr$1c3igv$ 1@ID-107532.news.uni-berlin.de>, Thomas 'PointedEars'
          Lahn <PointedEars@we b.de> writes:
          [color=blue]
          >Because it's evil[tm] eval(...).[/color]

          eval, in and of itself, is not evil. Its mis-use and the mis-understanding of
          its appropriate use is what makes it evil. I know of at least 2 places where
          its use is actually *good* .
          --
          Randy

          Comment

          • Lasse Reichstein Nielsen

            #20
            Re: eval

            hikksnotathome@ aol.com (HikksNotAtHome ) writes:
            [color=blue]
            > eval, in and of itself, is not evil. Its mis-use and the mis-understanding of
            > its appropriate use is what makes it evil. I know of at least 2 places where
            > its use is actually *good* .[/color]

            Let us hear :)

            /L 'I use it too, but only in one place'
            --
            Lasse Reichstein Nielsen - lrn@hotpop.com
            JS Test Bench: <URL:http://www.infimum.dk/HTML/javascript/jstest6.html>
            'Faith without judgement merely degrades the spirit divine.'

            Comment

            • Richard Cornford

              #21
              Re: eval

              "Stuart" <kffgtr@yytd.gf t> wrote in message
              news:bobsev$i4a $1@newsg2.svr.p ol.co.uk...[color=blue]
              > Many thanks Lee.....works perfectly[/color]
              <snip>[color=blue][color=green][color=darkred]
              >>>>>for(var i=0;i<pics;i++) {
              >>>>> eval('img'+i) = new Image(wth,hgt)
              >>>>> eval('img'+i+'. src') = 'http://www.mypics/'+i+'1.gif'[/color][/color][/color]
              <snip>

              What you are attempting is property access based on the result of
              evaluating an expression. That is a common misuse of eval and never
              necessary as JavaScript has this capability built in to its square
              bracket property accessor syntax. See:-

              <URL: http://jibbering.com/faq/#FAQ4_39 >

              - and the linked article for more information.

              Although, in this particular context where the only variable part of the
              expression is an integer that acts as an index, Lee's Array based
              approach is better suited to the problem.

              Richard.


              Comment

              • Albert Wagner

                #22
                Re: eval

                On Wed, 05 Nov 2003 23:31:44 +0100
                Thomas 'PointedEars' Lahn <PointedEars@we b.de> wrote:
                [color=blue]
                > Stuart wrote:[/color]
                <snip>[color=blue][color=green]
                > > why have you posted a somewhat
                > > pointless reply TWICE ??[/color]
                >
                > I did not. Please get informed about control messages like Cancel.[/color]
                <snip>

                Yes, you did. You should get informed when Cancel works and when it
                doesn't.

                --
                Life is an offensive, directed against the repetitious mechanism of the
                Universe.
                --Alfred North Whitehead (1861-1947)

                Comment

                • HikksNotAtHome

                  #23
                  Re: eval

                  In article <ekwmqr5a.fsf@h otpop.com>, Lasse Reichstein Nielsen <lrn@hotpop.com >
                  writes:
                  [color=blue]
                  >hikksnotathome @aol.com (HikksNotAtHome ) writes:
                  >[color=green]
                  >> eval, in and of itself, is not evil. Its mis-use and the mis-understanding[/color]
                  >of[color=green]
                  >> its appropriate use is what makes it evil. I know of at least 2 places[/color]
                  >where[color=green]
                  >> its use is actually *good* .[/color]
                  >
                  >Let us hear :)[/color]

                  The first one, John Stocktons site has a textarea for input of script to test
                  it. When testing it, it seems to be the best way to do it (using eval).

                  The other one was a problem I had a while back (it was discussed here) where I
                  had a select list that had fractions as its value. The fractions were random in
                  the sense that they weren't always the same denominator. The problem was trying
                  to convert the fraction to a decimal. It turned out that, in some browsers,
                  eval performed at the same level as splitting on the / and then dividing.

                  Where's the one place you use it?
                  --
                  Randy

                  Comment

                  • Richard Cornford

                    #24
                    Re: eval

                    "Lasse Reichstein Nielsen" <lrn@hotpop.com > wrote in message
                    news:ekwmqr5a.f sf@hotpop.com.. .[color=blue]
                    >hikksnotathome @aol.com (HikksNotAtHome ) writes:
                    >[color=green]
                    >>eval, in and of itself, is not evil. Its mis-use and the
                    >>mis-understanding of its appropriate use is what makes it
                    >>evil. I know of at least 2 places where its use is actually
                    >>*good* .[/color][/color]
                    [color=blue]
                    > Let us hear :)[/color]

                    I imagine that Randy is in part alluding to the thread from
                    17th August 2003 with the subject "Alternativ e to eval",
                    which, because the application was for an Intranet, did not
                    find a better alternative.

                    Another possibility where eval seems to be required is the full
                    emulation of Function.protot ype.apply for IE 4 and 5.0 (which
                    don't implement it):-

                    <URL:
                    http://groups.google.com/groups?selm...ws.demon.co.uk[color=blue]
                    >[/color]

                    A full emulation of function.protot ype.apply may be required
                    if the curry function being discussed earlier this week was to
                    be used with the older IE/JScript versions.

                    Richard.


                    Comment

                    • Douglas Crockford

                      #25
                      Re: eval

                      > Another possibility where eval seems to be required is the full[color=blue]
                      > emulation of Function.protot ype.apply for IE 4 and 5.0 (which
                      > don't implement it):-[/color]

                      Function.protot ype.apply = function (o, a) {
                      var r, x = '____apply';
                      o[x] = this;
                      switch ((a && a.length) || 0) {
                      case 0:
                      r = o[x]();
                      break;
                      case 1:
                      r = o[x](a[0]);
                      break;
                      case 2:
                      r = o[x](a[0], a[1]);
                      break;
                      case 3:
                      r = o[x](a[0], a[1], a[2]);
                      break;
                      case 4:
                      r = o[x](a[0], a[1], a[2], a[3]);
                      break;
                      case 5:
                      r = o[x](a[0], a[1], a[2], a[3], a[4]);
                      break;
                      case 6:
                      r = o[x](a[0], a[1], a[2], a[3], a[4], a[5]);
                      break;
                      default:
                      alarm('Time to add another case to apply.');
                      }
                      delete o[x];
                      return r;
                      };

                      The only thing I use eval for is converting JSON strings to objects.



                      Comment

                      • Richard Cornford

                        #26
                        Re: eval

                        "Douglas Crockford" <nospam@laserli nk.net> wrote in message
                        news:dcc7a$3fa9 c675$436563ac$2 0634@msgid.mega newsservers.com ...[color=blue][color=green]
                        >> ... full emulation of Function.protot ype.apply ...[/color][/color]
                        <snip>[color=blue]
                        > default:
                        > alarm('Time to add another case to apply.');
                        > }
                        > delete o[x];
                        > return r;
                        > };[/color]

                        Which is why I specifically said "full emulation". I freely admit (and
                        explained in the post I referenced) that in all "real world"
                        applications of apply a partial emulation, that does not require eval,
                        would be sufficient.

                        I mentioned the apply emulation in relation to the curry function(s)
                        from "Creating true copies (of objects) in JS (possible?)" because, if
                        that function is to be written to accept a theoretically unlimited
                        number of parameters it will need a full emulation of apply. On the
                        other hand, if it is accepted that in actual applications of that type
                        of function there will be a known upper limit to the number of
                        parameters needed, then the curry function does not need to use apply at
                        all.

                        Richard.


                        Comment

                        • Thomas 'PointedEars' Lahn

                          #27
                          [OT] Cancel (was: eval)

                          Albert Wagner wrote:
                          [color=blue]
                          > Thomas 'PointedEars' Lahn <PointedEars@we b.de> wrote:[color=green]
                          >> Stuart wrote:[color=darkred]
                          >> > why have you posted a somewhat
                          >> > pointless reply TWICE ??[/color]
                          >>
                          >> I did not. Please get informed about control messages like Cancel.[/color]
                          >
                          > Yes, you did. You should get informed when Cancel works and when it
                          > doesn't.[/color]

                          Hm, either your news server does not obey Cancel (which is alas not yet
                          backed up by RFCs) or it could be a bug in Mozilla/5.0 rv:1.5 MailNews.
                          Unfortunately, I don't have access to control.cancel on my news server.

                          Could you please post the message ID of the dupe, so I can check that?


                          PointedEars

                          Comment

                          • Thomas 'PointedEars' Lahn

                            #28
                            Re: [OT] Cancel

                            Thomas 'PointedEars' Lahn wrote:
                            [color=blue]
                            > Hm, either your news server does not obey Cancel (which is alas not yet
                            > backed up by RFCs) or it could be a bug in Mozilla/5.0 rv:1.5 MailNews.
                            > Unfortunately, I don't have access to control.cancel on my news server.
                            >
                            > Could you please post the message ID of the dupe, so I can check that?[/color]

                            Not necessary. I've downloaded messages from another news server with
                            another newsreader and there was only one posting from me in this thread.
                            The Cancel worked and Mozilla is not buggy on that. If you see dupes either
                            your news server did not (yet) obey it or your newsreader does not provide
                            appropriate feedback.


                            HTH

                            PointedEars

                            Comment

                            • Lasse Reichstein Nielsen

                              #29
                              Re: eval

                              hikksnotathome@ aol.com (HikksNotAtHome ) writes:
                              [color=blue]
                              > The first one, John Stocktons site has a textarea for input of
                              > script to test it. When testing it, it seems to be the best way to
                              > do it (using eval).
                              >
                              > The other one was a problem I had a while back (it was discussed
                              > here) where I had a select list that had fractions as its value.[/color]

                              I remember that :)
                              [color=blue]
                              > The fractions were random in the sense that they weren't always the
                              > same denominator. The problem was trying to convert the fraction to
                              > a decimal. It turned out that, in some browsers, eval performed at
                              > the same level as splitting on the / and then dividing.[/color]

                              If it was only at the same level, then I wouldn't use eval. You need
                              total control of the arguments to eval (or a syntax check), which should
                              outweigh the advantage you get from shorter code.

                              As for speed. As far as I can see, eval is *much* slower (more tha 5x)
                              than using split in IE 6. A little faster yet is finding the "/" with
                              indexOf and using substring to get the parts:
                              var i = str.indexOf("/");
                              return str.substr(0,i)/str.substr(i+1) ;

                              In Opera 7.2, split was fastest and eval slowest. In MozFB, split and
                              eval are comparable. In Netscape 4.8, eval is actually twice as fast
                              as split, and 1.5 times as fast as using substring. It is generally
                              slower than the other browsers, though.
                              [color=blue]
                              > Where's the one place you use it?[/color]

                              A text area for input of scripts (actually the one that I link to in
                              this signature).

                              /L
                              --
                              Lasse Reichstein Nielsen - lrn@hotpop.com
                              JS Test Bench: <URL:http://www.infimum.dk/HTML/javascript/jstest6.html>
                              'Faith without judgement merely degrades the spirit divine.'

                              Comment

                              • HikksNotAtHome

                                #30
                                Re: [OT] Cancel

                                In article <bod8k8$csj$1@p iggy.rz.tu-ilmenau.de>, Thomas 'PointedEars' Lahn
                                <PointedEars@we b.de> writes:
                                [color=blue]
                                >Not necessary. I've downloaded messages from another news server with
                                >another newsreader and there was only one posting from me in this thread.
                                >The Cancel worked and Mozilla is not buggy on that. If you see dupes either
                                >your news server did not (yet) obey it or your newsreader does not provide
                                >appropriate feedback.[/color]

                                Go to groups.google.c om and look at the archive. http://tinyurl.com/tw51 and it
                                does indeed show the duplicate posts. Message 38 and 39 in the eval thread.

                                One should practice what they preach.
                                --
                                Randy

                                Comment

                                Working...