eval(string[, object]) example

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • C.W.Holeman II

    eval(string[, object]) example

    I am looking for an example using the object argument to eval().

    The MDN Web Docs site provides information about Open Web technologies including HTML, CSS, and APIs for both Web sites and progressive web apps.


    --
    C.W.Holeman II | cwhii@Julian5Lo cals.com-5 http://JulianLocals.com/cwhii
    To only a fraction of the human race does God give the privilege of
    earning one's bread doing what one would have gladly pursued free, for
    passion. I am very thankful. The Mythical Man-Month Epilogue/F.P.Brooks
  • Duncan Booth

    #2
    Re: eval(string[, object]) example

    "C.W.Holema n II" <cwhii_google_s pam@yahoo.comwr ote:
    I am looking for an example using the object argument to eval().
    eval("alert(x); ", {x:42});

    Comment

    • Randy Webb

      #3
      Re: eval(string[, object]) example

      C.W.Holeman II said the following on 4/26/2007 3:35 PM:
      I am looking for an example using the object argument to eval().
      Why? A better question is what are the scenarios where eval is needed
      because an alternative isn't available (or a reasonable alternative).

      --
      Randy
      Chance Favors The Prepared Mind
      comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
      Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

      Comment

      • Dr J R Stockton

        #4
        Re: eval(string[, object]) example

        In comp.lang.javas cript message <1331s9k2q7hhe2 c@corp.supernew s.com>,
        Thu, 26 Apr 2007 11:35:52, C.W.Holeman II <cwhii_google_s pam@yahoo.com>
        posted:
        >I am looking for an example using the object argument to eval().
        <URL:http://www.merlyn.demo n.co.uk/holidays.htmapp lies eval to
        DataBox.value - that's more than just an Object, but a major part of it
        is an Object assignment, and I see nothing to prevent the code being
        adjusted so that DataBox.value contained a single Object Literal, {...}.

        Or did you want a simple example?

        --
        (c) John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v6.05 IE 6.
        Web <URL:http://www.merlyn.demo n.co.uk/- w. FAQish topics, links, acronyms
        PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/- see 00index.htm
        Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.

        Comment

        • -Lost

          #5
          Re: eval(string[, object]) example

          Randy Webb wrote:
          C.W.Holeman II said the following on 4/26/2007 3:35 PM:
          >I am looking for an example using the object argument to eval().
          >
          Why? A better question is what are the scenarios where eval is needed
          because an alternative isn't available (or a reasonable alternative).
          Dang it. I just ran across an article within the last day or so and now
          cannot find it to save my life.

          It was something about "this is a fairly advanced use of eval." For
          some reason I thought it even mentioned "kung fu."

          This would have been a perfect article in response to this thread.

          Maybe someone else can find it?

          --
          -Lost
          Remove the extra words to reply by e-mail. Don't e-mail me. I am
          kidding. No I am not.

          Comment

          • C.W.Holeman II

            #6
            Re: eval(string[, object]) example

            Duncan Booth wrote:
            "C.W.Holema n II" <cwhii_google_s pam@yahoo.comwr ote:
            >
            >I am looking for an example using the object argument to eval().
            >
            eval("alert(x); ", {x:42});
            Changed from the XSLT file generating an id which produced output like:

            <emleo:consta nt
            emle_id="EMLE_i d0x588"
            emle_on_load="e mleNextOnChange (emleGetElement ById('EMLE_id0x 588'));"
            >
            to simply this fixed string:

            <emleo:consta nt emle_on_load="e mleNextOnChange (thisElement);" >

            The javascript changed from no object passed:

            eval(emleOnChan ge);

            to adding the context at run-time:

            eval(
            emleOnChange,
            {thisElement:ch angeNodePathRes ult.singleNodeV alue.ownerEleme nt}
            );





            --
            C.W.Holeman II cwhii@Julian5Lo cals.com -5 http://JulianLocals.com/cwhii
            To only a fraction of the human race does God give the privilege of
            earning one's bread doing what one would have gladly pursued free, for
            passion. I am very thankful. The Mythical Man-Month Epilogue/F.P.Brooks

            Comment

            • -Lost

              #7
              Re: eval(string[, object]) example

              -Lost wrote:
              Randy Webb wrote:
              >C.W.Holeman II said the following on 4/26/2007 3:35 PM:
              >>I am looking for an example using the object argument to eval().
              >>
              >Why? A better question is what are the scenarios where eval is needed
              >because an alternative isn't available (or a reasonable alternative).
              >
              Dang it. I just ran across an article within the last day or so and now
              cannot find it to save my life.
              >
              It was something about "this is a fairly advanced use of eval." For
              some reason I thought it even mentioned "kung fu."
              >
              This would have been a perfect article in response to this thread.
              >
              Maybe someone else can find it?
              The only reason I found this is because I posted here, I am sure it is a
              conspiracy.

              Anyway...



              Which he then discusses in depth here:



              I make no claims about its validity or worthwhileness.

              --
              -Lost
              Remove the extra words to reply by e-mail. Don't e-mail me. I am
              kidding. No I am not.

              Comment

              • C.W.Holeman II

                #8
                Re: eval(string[, object]) example

                C.W.Holeman II wrote:
                Duncan Booth wrote:
                >"C.W.Holema n II" <cwhii_google_s pam@yahoo.comwr ote:
                >>
                >>I am looking for an example using the object argument to eval().
                >>
                > eval("alert(x); ", {x:42});
                >
                Changed from the XSLT file generating an id which produced output like:
                >
                <emleo:consta nt
                emle_id="EMLE_i d0x588"
                emle_on_load="e mleNextOnChange (emleGetElement ById('EMLE_id0x 588'));"
                >
                >
                to simply this fixed string:
                >
                <emleo:consta nt emle_on_load="e mleNextOnChange (thisElement);" >
                >
                The javascript changed from no object passed:
                >
                eval(emleOnChan ge);
                >
                to adding the context at run-time:
                >
                eval(
                emleOnChange,
                {thisElement:ch angeNodePathRes ult.singleNodeV alue.ownerEleme nt}
                );
                >



                >
                Using:

                Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3)
                Gecko/20070309 Firefox/2.0.0.3

                --
                C.W.Holeman II cwhii@Julian5Lo cals.com-5 http://JulianLocals.com/cwhii
                To only a fraction of the human race does God give the privilege of
                earning one's bread doing what one would have gladly pursued free, for
                passion. I am very thankful. The Mythical Man-Month Epilogue/F.P.Brooks

                Comment

                • C.W.Holeman II

                  #9
                  Re: eval(string[, object]) example

                  Randy Webb wrote:
                  C.W.Holeman II said the following on 4/26/2007 3:35 PM:
                  >I am looking for an example using the object argument to eval().
                  >
                  Why? A better question is what are the scenarios where eval is needed
                  because an alternative isn't available (or a reasonable alternative).
                  >
                  Until now I have used a generated id to identify the element for a fake
                  callback attribute. Since an HTML onchange attribute is able to pass
                  'this'. I saw the eval() object argument as possibly addressing this
                  issue. What I have changed it to is:

                  <emleo:consta nt emle_on_load="e mleNextOnChange (thisElement);" >

                  which removes the need of the XSLT file from having to generate the id
                  and passing it to the callback. But, this has the javascript code:

                  eval(
                  emleOnChange,
                  {thisElement:ch angeNodePathRes ult.singleNodeV alue.ownerEleme nt}
                  );

                  needing to know the name 'thisElement' which is used in the XSLT file.





                  So, is this better?

                  Is there a way to hand the context over to the callback without having
                  'thisElement' hard coded in the XSLT file?

                  --
                  C.W.Holeman II cwhii@Julian5Lo cals.com -5 http://JulianLocals.com/cwhii
                  To only a fraction of the human race does God give the privilege of
                  earning one's bread doing what one would have gladly pursued free, for
                  passion. I am very thankful. The Mythical Man-Month Epilogue/F.P.Brooks

                  Comment

                  • Peter Michaux

                    #10
                    Re: eval(string[, object]) example

                    On Apr 26, 1:11 pm, Duncan Booth <duncan.bo...@i nvalid.invalidw rote:
                    "C.W.Holema n II" <cwhii_google_s ...@yahoo.comwr ote:
                    I am looking for an example using the object argument to eval().
                    >
                    eval("alert(x); ", {x:42});
                    eval() doesn't take a second argument in JavaScript. I know it does in
                    Ruby and it would be nice in JavaScript. Either way there are not many
                    more than three places were eval() is considered acceptably used in
                    JavaScript and that is where the code to be evaluated arrives to the
                    JavaScript as a sting.

                    Peter

                    Comment

                    • Duncan Booth

                      #11
                      Re: eval(string[, object]) example

                      Dr J R Stockton <jrs@merlyn.dem on.co.ukwrote:
                      In comp.lang.javas cript message <1331s9k2q7hhe2 c@corp.supernew s.com>,
                      Thu, 26 Apr 2007 11:35:52, C.W.Holeman II <cwhii_google_s pam@yahoo.com>
                      posted:
                      >
                      >>I am looking for an example using the object argument to eval().
                      >
                      ><URL:http://www.merlyn.demo n.co.uk/holidays.htmapp lies eval to
                      DataBox.value - that's more than just an Object, but a major part of it
                      is an Object assignment, and I see nothing to prevent the code being
                      adjusted so that DataBox.value contained a single Object Literal, {...}.
                      >
                      Or did you want a simple example?
                      >
                      He was asking about the non-standard optional second argument to eval which
                      is supported by Mozilla/Firefox browsers. At least given the reference he
                      quoted I think that was what he was asking about.

                      Comment

                      • Randy Webb

                        #12
                        Re: eval(string[, object]) example

                        Peter Michaux said the following on 4/26/2007 10:56 PM:
                        On Apr 26, 1:11 pm, Duncan Booth <duncan.bo...@i nvalid.invalidw rote:
                        >"C.W.Holema n II" <cwhii_google_s ...@yahoo.comwr ote:
                        >>I am looking for an example using the object argument to eval().
                        > eval("alert(x); ", {x:42});
                        >
                        eval() doesn't take a second argument in JavaScript.
                        Sure it does. JScript doesn't but Javascript - in Mozilla based browsers
                        - can accept it.

                        --
                        Randy
                        Chance Favors The Prepared Mind
                        comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
                        Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

                        Comment

                        Working...