@@unscopable
symbol property contains property names that were not included in the ECMAScript standard prior to the ES2015 version. These properties are excluded from
with
statement bindings.
The default array properties that are excluded from
with
bindings are:
见
Symbol.unscopables
for how to set
unscopables
for your own objects.
特性属性在
Array.prototype[@@unscopables]
|
|
|---|---|
| 可写 | no |
| 可枚举 | no |
| 可配置 | yes |
with
environments
The following code works fine in ES5 and below. However, in ECMAScript 2015 and later, the
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
语句。
var keys = [];
with (Array.prototype) {
keys.push('something');
}
Object.keys(Array.prototype[Symbol.unscopables]);
// ["copyWithin", "entries", "fill", "find", "findIndex",
// "includes", "keys", "values"]
| 规范 |
|---|
|
ECMAScript (ECMA-262)
The definition of 'Array.prototype[@@unscopables]' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@unscopables
|
Chrome 38 | Edge 12 | Firefox 48 | IE No | Opera 25 | Safari 10 | WebView Android 38 | Chrome Android 38 | Firefox Android 48 | Opera Android 25 | Safari iOS 10 | Samsung Internet Android 3.0 | nodejs 0.12 |
完整支持
不支持
Array
Array.prototype.length
Array.prototype[@@unscopables]
Array.from()
Array.isArray()
Array.of()
Array.prototype.concat()
Array.prototype.copyWithin()
Array.prototype.entries()
Array.prototype.every()
Array.prototype.fill()
Array.prototype.filter()
Array.prototype.find()
Array.prototype.findIndex()
Array.prototype.flat()
Array.prototype.flatMap()
Array.prototype.forEach()
Array.prototype.includes()
Array.prototype.indexOf()
Array.prototype.join()
Array.prototype.keys()
Array.prototype.lastIndexOf()
Array.prototype.map()
Array.prototype.pop()
Array.prototype.push()
Array.prototype.reduce()
Array.prototype.reduceRight()
Array.prototype.reverse()
Array.prototype.shift()
Array.prototype.slice()
Array.prototype.some()
Array.prototype.sort()
Array.prototype.splice()
Array.prototype.toLocaleString()
Array.prototype.toSource()
Array.prototype.toString()
Array.prototype.unshift()
Array.prototype.values()
Array.prototype[@@iterator]()
get Array[@@species]
Function
Object
Object.prototype.__defineGetter__()
Object.prototype.__defineSetter__()
Object.prototype.__lookupGetter__()
Object.prototype.__lookupSetter__()
Object.prototype.hasOwnProperty()
Object.prototype.isPrototypeOf()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toSource()
Object.prototype.toString()
Object.prototype.valueOf()
Object.setPrototypeOf()