The @@unscopables data property of Array.prototype is shared by all Array instances. It contains property names that were not included in the ECMAScript standard prior to the ES2015 version and that are ignored for with statement-binding purposes.
On this page
Array.prototype[@@unscopables]
Value
A null-prototype object with property names given below and their values set to true.
Property attributes of Array.prototype[@@unscopables] |
|
|---|---|
| Writable | no |
| Enumerable | no |
| Configurable | yes |
Description
The default Array properties that are ignored for with statement-binding purposes are:
at()copyWithin()entries()fill()find()findIndex()findLast()findLastIndex()flat()flatMap()includes()keys()toReversed()toSorted()toSpliced()values()
Array.prototype[@@unscopables] is an empty object only containing all the above property names with the value true. Its prototype is null, so Object.prototype properties like toString won't accidentally be made unscopable, and a toString() within the with statement will continue to be called on the array.
See Symbol.unscopables for how to set unscopable properties for your own objects.
Examples
Imagine the keys.push('something') call below is in code that was written prior to ECMAScript 2015.
var keys = [];
with (Array.prototype) {
keys.push("something");
}
When ECMAScript 2015 introduced the Array.prototype.keys() method, if the @@unscopables data property had not also been introduced, that keys.push('something') call would break — because the JavaScript runtime would have interpreted keys as being the Array.prototype.keys() method, rather than the keys array defined in the example code.
So the @@unscopables data property for Array.prototype causes the Array properties introduced in ECMAScript 2015 to be ignored for with statement-binding purposes — allowing code that was written prior to ECMAScript 2015 to continue working as expected, rather than breaking.
Specifications
Browser compatibility
| Desktop | Mobile | Server | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | Deno | Node.js | ||
@@unscopables |
38 | 12 | 48 | 25 | 10 | 38 | 48 | 25 | 10 | 3.0 | 38 | 1.0 | 0.12.0 | |
See also
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/@@unscopables