Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1038418 of Array.prototype[@@unscopables]

  • Revision slug: Web/JavaScript/Reference/Global_Objects/Array/@@unscopables
  • Revision title: Array.prototype[@@unscopables]
  • Revision id: 1038418
  • Created:
  • Creator: evilpie
  • Is current revision? No
  • Comment

Revision Content

{{JSRef}}

The @@unscopable symbol property contains property names that were not included in the ECMAScript standard prior to the ES2015 (ES6) version. These properties are excluded from with statement bindings.

{{js_property_attributes(0,0,1)}}

Syntax

arr[Symbol.unscopables]

Description

The default array properties that are excluded from with bindings are: copyWithin, entries, fill, find, findIndex, includes, keys, and values.

See {{jsxref("Symbol.unscopables")}} for how to set unscopables for your own objects.

Examples

The following code works fine in ES5 and below. However, in ECMAScript 2015 (ES6) and later, the {{jsxref("Array.prototype.keys()")}} method was introduced. That means that inside with environments, "keys" would now be the method and not the variable. This is where now the built-in @@unscopables Array.prototype[@@unscopables] symbol property comes into play and prevents that some of the Array methods are being scoped into the with statement.

var keys = [];

with(Array.protoype) {
  keys.push("something");
}

Object.keys(Array.prototype[Symbol.unscopables]); 
// ["copyWithin", "entries", "fill", "find", "findIndex", 
//  "includes", "keys", "values"]

Specifications

Specification Status Comment
{{SpecName('ES6', '#sec-array.prototype-@@unscopables', 'Array.prototype[@@unscopables]')}} {{Spec2('ES6')}} Initial definition.
{{SpecName('ESDraft', '#sec-array.prototype-@@unscopables', 'Array.prototype[@@unscopables]')}} {{Spec2('ESDraft')}}  

Browser compatibility

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{CompatNo}} {{CompatGeckoDesktop("48")}} {{CompatNo}} {{CompatNo}} {{CompatNo}}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatNo}} {{CompatNo}} {{CompatGeckoMobile("48")}} {{CompatNo}} {{CompatNo}} {{CompatNo}}

See also

  • {{jsxref("Symbol.unscopables")}}

Revision Source

<div>{{JSRef}}</div>

<p>The <code><strong>@@unscopable</strong></code> symbol property contains property names that were not included in the ECMAScript standard prior to the ES2015 (ES6) version. These properties are excluded from <code><a href="/en-US/docs/Web/JavaScript/Reference/Statements/with">with</a></code> statement bindings.</p>

<p>{{js_property_attributes(0,0,1)}}</p>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox">
<var>arr</var>[Symbol.unscopables]</pre>

<h2 id="Description">Description</h2>

<p>The default array properties that are excluded from <code>with</code> bindings are: copyWithin, entries, fill, find, findIndex, includes, keys, and values.</p>

<p>See {{jsxref("Symbol.unscopables")}} for how to set <code>unscopables</code> for your own objects.</p>

<h2 id="Examples">Examples</h2>

<p>The following code works fine in ES5 and below. However, in ECMAScript 2015 (ES6) and later, the {{jsxref("Array.prototype.keys()")}} method was introduced. That means that inside <code>with</code> environments, "keys" would now be the method and not the variable. This is where now the built-in <code>@@unscopables</code> <code>Array.prototype[@@unscopables]</code> symbol property comes into play and prevents that some of the Array methods are being scoped into the <code>with</code> statement.</p>

<pre class="brush: js">
var keys = [];

with(Array.protoype) {
  keys.push("something");
}

Object.keys(Array.prototype[Symbol.unscopables]); 
// ["copyWithin", "entries", "fill", "find", "findIndex", 
//  "includes", "keys", "values"]</pre>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-array.prototype-@@unscopables', 'Array.prototype[@@unscopables]')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td>Initial definition.</td>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-array.prototype-@@unscopables', 'Array.prototype[@@unscopables]')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td>&nbsp;</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<div>{{CompatibilityTable}}</div>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatGeckoDesktop("48")}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Chrome for Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatGeckoMobile("48")}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="See_also">See also</h2>

<ul>
 <li>{{jsxref("Symbol.unscopables")}}</li>
</ul>
Revert to this revision