From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../global_objects/array/@@unscopables/index.html | 78 ++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 files/ja/web/javascript/reference/global_objects/array/@@unscopables/index.html (limited to 'files/ja/web/javascript/reference/global_objects/array/@@unscopables/index.html') diff --git a/files/ja/web/javascript/reference/global_objects/array/@@unscopables/index.html b/files/ja/web/javascript/reference/global_objects/array/@@unscopables/index.html new file mode 100644 index 0000000000..478ccbfb0e --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/array/@@unscopables/index.html @@ -0,0 +1,78 @@ +--- +title: 'Array.prototype[@@unscopables]' +slug: Web/JavaScript/Reference/Global_Objects/Array/@@unscopables +tags: + - Array + - ECMAScript 2015 + - JavaScript + - Property + - Prototype +translation_of: Web/JavaScript/Reference/Global_Objects/Array/@@unscopables +--- +
{{JSRef}}
+ +

@@unscopable シンボルプロパティには、 ES2015 以前の ECMAScript 標準には含まれていないプロパティ名があります。それらのプロパティは、with 文のバインディングから除外されます。

+ +

解説

+ +

with バインディングから除外される既定の配列プロパティは次のとおりです。

+ + + +

自作オブジェクトに unscopables を設定する方法については、 {{jsxref("Symbol.unscopables")}} を見てください。

+ +

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

+ +

+ +

with 環境内での使用

+ +

次のコードは、 ES5 以下であれば正常に動作します。しかし、 ECMAScript 2015 以降では {{jsxref("Array.prototype.keys()")}} メソッドが導入されました。つまり、with 環境内では、 "keys" はメソッドであり、変数ではありません。ここが組込み @@unscopables の役立つ場所です。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"]
+ +

仕様書

+ + + + + + + + + + + + +
仕様書
{{SpecName('ESDraft', '#sec-array.prototype-@@unscopables', 'Array.prototype[@@unscopables]')}}
+ +

ブラウザーの互換性

+ +
+ + +

{{Compat("javascript.builtins.Array.@@unscopables")}}

+
+ +

関連情報

+ + -- cgit v1.2.3-54-g00ecf