Apply your JS skills to key Mozilla projects as an MDN Fellow! http://mzl.la/MDNFellowship

mozilla

Compare Revisions

with

Change Revisions

Revision 417111:

Revision 417111 by Sheppy on

Revision 431229:

Revision 431229 by claudepache on

Title:
with
with
Slug:
Web/JavaScript/Reference/Statements/with
Web/JavaScript/Reference/Statements/with
Content:

Revision 417111
Revision 431229
tt97      <li>Con: Code using <code>with</code> may not be forward co
 >mpatible, especially when used with something else than a plain o
 >bject. For example, consider this example:
98        <div>
99          <pre class="brush:js">
100function f(foo, values) {
101    with (foo) {
102        console.log(values)
103    }
104}
105</pre>
106          <p>
107            If you call <code>f([1,2,3], obj)</code> in an ECMASc
 >ript 5 environment, then the <code>values</code> reference inside
 > the <code>with</code> statement will resolve to <code>obj</code>
 >. However, ECMAScript 6 introduces a <code>values</code> property
 > on <code><a href="/en-US/docs/Web/JavaScript/Reference/Global_Ob
 >jects/Array/prototype">Array.prototype</a></code> (so that it wil
 >l be available on every array). So, in a JavaScript environment t
 >hat supports ECMAScript 6, the <code>values</code> reference insi
 >de the <code>with</code> statement will resolve to <code>[1,2,3].
 >values</code>.
108          </p>
109        </div>
110      </li>

Back to History