mozilla

Revision 134211 of eval

  • Revision slug: Talk:JavaScript/Reference/Global_Objects/eval
  • Revision title: eval
  • Revision id: 134211
  • Created:
  • Creator: Random832
  • Is current revision? No
  • Comment 65 words added; page display name changed to 'eval'

Revision Content

There are some bad examples here.

First, all statements should have semicolons. Although optional, it should definitely be encouraged.

Second, the last example has this: eval ("document.forms{{ mediawiki.external("0") }}." + textObject + ".value") = newValue. That is a really bad use of eval. eval shouldn't be used at all there! It should be document.forms{{ mediawiki.external("0") }}{{ mediawiki.external('textObject') }}.value

--Maian 23:19, 24 Aug 2005 (PDT)

This is a wiki, so go ahead and fix this. If someone thinks your changes are inappropriate (I'm not talking about the changes you suggested here), they can revert the page and explain why they did so on the talk page. --Nickolay 02:13, 25 Aug 2005 (PDT)

I found only one missing semi-colon, which I added. Any others needed were added before I stumbled across this page.

I'd like to see more discussion of the second argument to eval and how it affects the result; that's the kind of information I was looking for. The description also needs to have information about error conditions added: what happens if the expression can't be parsed, for instance, or if evaluation fails for other reasons.

--Fdrake 02:18, 04 Jan 2008 (EDT)

---- Is there a function to compile a statement to be evaluated multiple times without recompiling every time? I tried new Function() but that won't automatically return the value of the last statement in the string, and if i add a "return" keyword it won't work at all with multiple statements. Random832 28 May 2009

Revision Source

<p>There are some bad examples here.</p>
<p>First, all statements should have semicolons. Although optional, it should definitely be encouraged.</p>
<p>Second, the last example has this: <code>eval ("document.forms{{ mediawiki.external("0") }}." + textObject + ".value") = newValue</code>. That is a <em>really</em> bad use of eval. eval shouldn't be used at all there! It should be <code>document.forms{{ mediawiki.external("0") }}{{ mediawiki.external('textObject') }}.value</code></p>
<p>--<a href="/User:Maian" title="User:Maian">Maian</a> 23:19, 24 Aug 2005 (PDT)</p>
<dl><dd> This is a wiki, so go ahead and fix this. If someone thinks your changes are inappropriate (I'm not talking about the changes you suggested here), they can revert the page and explain why they did so on the talk page. --<a href="/User:Nickolay" title="User:Nickolay">Nickolay</a> 02:13, 25 Aug 2005 (PDT) </dd></dl>
<p>I found only one missing semi-colon, which I added. Any others needed were added before I stumbled across this page.</p>
<p>I'd like to see more discussion of the second argument to <code>eval</code> and how it affects the result; that's the kind of information I was looking for. The description also needs to have information about error conditions added: what happens if the expression can't be parsed, for instance, or if evaluation fails for other reasons.</p>
<p>--<a href="/User:Fdrake1" title="User:Fdrake1">Fdrake</a> 02:18, 04 Jan 2008 (EDT)</p>
<p>---- Is there a function to compile a statement to be evaluated multiple times without recompiling every time? I tried new Function() but that won't automatically return the value of the last statement in the string, and if i add a "return" keyword it won't work at all with multiple statements. <a href="https://developer.mozilla.org/User:Random832" rel="custom">Random832</a> 28 May 2009</p>
Revert to this revision