473,396 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

eval(string[, object]) example

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

http://developer.mozilla.org/en/docs...Functions:eval

--
C.W.Holeman II | cw***@Julian5Locals.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
Apr 26 '07 #1
11 1963
"C.W.Holeman II" <cw***************@yahoo.comwrote:
I am looking for an example using the object argument to eval().
eval("alert(x);", {x:42});
Apr 26 '07 #2
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.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 26 '07 #3
In comp.lang.javascript message <13*************@corp.supernews.com>,
Thu, 26 Apr 2007 11:35:52, C.W.Holeman II <cw***************@yahoo.com>
posted:
>I am looking for an example using the object argument to eval().
<URL:http://www.merlyn.demon.co.uk/holidays.htmapplies 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.demon.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/- see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Apr 26 '07 #4
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.
Apr 26 '07 #5
Duncan Booth wrote:
"C.W.Holeman II" <cw***************@yahoo.comwrote:
>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:constant
emle_id="EMLE_id0x588"
emle_on_load="emleNextOnChange(emleGetElementById( 'EMLE_id0x588'));"
>
to simply this fixed string:

<emleo:constant emle_on_load="emleNextOnChange(thisElement);">

The javascript changed from no object passed:

eval(emleOnChange);

to adding the context at run-time:

eval(
emleOnChange,
{thisElement:changeNodePathResult.singleNodeValue. ownerElement}
);

http://emle.sourceforge.net/emle0200...le_lab_009.xml
http://emle.sourceforge.net/emle0200...le_lab_009.xsl
http://emle.sourceforge.net/emle0200...mle_lab_009.js

--
C.W.Holeman II cw***@Julian5Locals.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
Apr 26 '07 #6
-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...

http://www.berniecode.com/blog/2007/...in-javascript/

Which he then discusses in depth here:

http://www.berniecode.com/writing/eval.html

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.
Apr 26 '07 #7
C.W.Holeman II wrote:
Duncan Booth wrote:
>"C.W.Holeman II" <cw***************@yahoo.comwrote:
>>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:constant
emle_id="EMLE_id0x588"
emle_on_load="emleNextOnChange(emleGetElementById( 'EMLE_id0x588'));"
>

to simply this fixed string:

<emleo:constant emle_on_load="emleNextOnChange(thisElement);">

The javascript changed from no object passed:

eval(emleOnChange);

to adding the context at run-time:

eval(
emleOnChange,
{thisElement:changeNodePathResult.singleNodeValue. ownerElement}
);

http://emle.sourceforge.net/emle0200...le_lab_009.xml
http://emle.sourceforge.net/emle0200...le_lab_009.xsl
http://emle.sourceforge.net/emle0200...mle_lab_009.js
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 cw***@Julian5Locals.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
Apr 27 '07 #8
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:constant emle_on_load="emleNextOnChange(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:changeNodePathResult.singleNodeValue. ownerElement}
);

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

http://emle.sourceforge.net/emle0200...le_lab_009.xml
http://emle.sourceforge.net/emle0200...le_lab_009.xsl
http://emle.sourceforge.net/emle0200...mle_lab_009.js

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 cw***@Julian5Locals.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
Apr 27 '07 #9
On Apr 26, 1:11 pm, Duncan Booth <duncan.bo...@invalid.invalidwrote:
"C.W.Holeman II" <cwhii_google_s...@yahoo.comwrote:
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

Apr 27 '07 #10
Dr J R Stockton <jr*@merlyn.demon.co.ukwrote:
In comp.lang.javascript message <13*************@corp.supernews.com>,
Thu, 26 Apr 2007 11:35:52, C.W.Holeman II <cw***************@yahoo.com>
posted:
>>I am looking for an example using the object argument to eval().

<URL:http://www.merlyn.demon.co.uk/holidays.htmapplies 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.
Apr 27 '07 #11
Peter Michaux said the following on 4/26/2007 10:56 PM:
On Apr 26, 1:11 pm, Duncan Booth <duncan.bo...@invalid.invalidwrote:
>"C.W.Holeman II" <cwhii_google_s...@yahoo.comwrote:
>>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.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 27 '07 #12

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

Similar topics

3
by: Grayson | last post by:
I have a need for an "Eval" function and found the perfect sample The problem is it doesn't like "IsDate" being fed into it. Any Ideas? seems like a missing reference, but I can't figure it out......
0
by: Michelle Keys | last post by:
Subject: DataBinder.Eval Error! Server Error in '/MSPOS' Application. ------------------------------------------------------------------------ -------- DataBinder.Eval:...
2
by: dm_dal | last post by:
I have a control on my webform that I am binding to a dataset. The issue is, the field value in the dataset is encrypted and I am trying to decrypt it during the binding process: Example: ...
18
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...
3
by: Csaba Gabor | last post by:
// Look ma! no evals! function eval2 (string, noReturn) { return Function((!noReturn ? "return " : "")+string)(); } var aR = eval2("/x/"); var Yo = eval2("{a:1, l:1, e:1, r:1, t:1}"); var a =...
4
by: Wilson | last post by:
Hello, How can i eval a string expression like String abc = ??"dt.Rows.Columns.ToString() + dt.Rows.Columns.ToString()" Thanks Wilson
9
by: Bob M | last post by:
If I define an expression or equation, how can I retrieve that expression as string literal? I want to do this so that I could avoid repetitive typing (or copy/paste/change) the same thing at two...
5
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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
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
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,...

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.