Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The difference between <code>(1,eval)</code> and plain old <code>eval</code> is that the former is a <em>value</em> and the latter is an lvalue. It would be more obvious if it were some other identifier:</p> <pre><code>var x; x = 1; (1, x) = 1; // syntax error, of course! </code></pre> <p>That is <code>(1,eval)</code> is an expression that yields <code>eval</code> (just as say, <code>(true &amp;&amp; eval)</code> or <code>(0 ? 0 : eval)</code> would), but it's not a reference to <code>eval</code>.</p> <p>Why do you care?</p> <p>Well, the Ecma spec considers a <em>reference</em> to <code>eval</code> to be a "direct eval call", but an expression that merely yields <code>eval</code> to be an indirect one -- and indirect eval calls are guaranteed to execute in global scope.</p> <p>Things I still don't know:</p> <ol> <li>Under what circumstance does a direct eval call <em>not</em> execute in global scope?</li> <li>Under what circumstance can the <code>this</code> of a function at global scope <em>not</em> yield the global object?</li> </ol> <p>Some more information can be gleaned <a href="http://perfectionkills.com/global-eval-what-are-the-options/">here</a>.</p> <p><strong>EDIT</strong> </p> <p>Apparently, the answer to my first question is, "almost always". A direct <code>eval</code> executes from the <em>current</em> scope. Consider the following code:</p> <pre><code>var x = 'outer'; (function() { var x = 'inner'; eval('console.log("direct call: " + x)'); (1,eval)('console.log("indirect call: " + x)'); })(); </code></pre> <p>Not surprisingly (heh-heh), this prints out:</p> <pre><code>direct call: inner indirect call: outer </code></pre> <p><strong>EDIT</strong></p> <p>After more experimentation, I'm going to provisionally say that <code>this</code> cannot be set to <code>null</code> or <code>undefined</code>. It can be set to other falsy values (0, '', NaN, false), but only <em>very</em> deliberately.</p> <p>I'm going to say your source is suffering from a mild and reversible cranio-rectal inversion and might want to consider spending a week programming in Haskell.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload