Array.prototype[@@unscopables]
@@unscopable
기호 속성은 ES2015 이전 ECMAScript 표준에 포함되지 않은 속성 이름을 포함합니다. 해당 속성들은 with
바인딩에서 제외됩니다.
구문
arr[Symbol.unscopables]
설명
with 바인딩에서 제외되는 배열의 기본 속성은 copyWithin, entries, fill, find, findIndex, includes, keys, values입니다.
자신의 객체에 대해 unscopables
를 설정하는 방법은 Symbol.unscopables
(en-US)를 참고하세요.
Property attributes of Array.prototype[@@unscopables] |
|
---|---|
Writable | 불가능 |
Enumerable | 불가능 |
Configurable | 가능 |
예제
아래 코드는 ES5 이하에서 잘 작동합니다. 그러나 ECMAScript 2015 이후 Array.prototype.keys()
메서드가 도입되었습니다. 이는 with
내부에서 "keys"가 변수가 아니라 메서드임을 의미합니다. 여기서 Array.prototype[@@unscopables]
가 개입하여 일부 배열 메서드가 with
범위에 묶이는 일을 방지합니다.
var keys = [];
with (Array.prototype) {
keys.push("something");
}
Object.keys(Array.prototype[Symbol.unscopables]);
// ["copyWithin", "entries", "fill", "find", "findIndex",
// "includes", "keys", "values"]
명세
Specification |
---|
ECMAScript Language Specification # sec-array.prototype-@@unscopables |
브라우저 호환성
BCD tables only load in the browser